Created
May 3, 2014 01:50
-
-
Save b1naryth1ef/4a500457d8915973f4dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sweg | |
def render_post(post, user): | |
return { | |
"name": post.name, | |
"author": user.username | |
} | |
def render_homepage(): | |
result = [] | |
posts = db.posts.get() | |
users = db.users.get() | |
# This could be sync | |
posts, users = sweg.wait(posts, users) | |
# This would run in any order | |
for post in sweg.map.async(posts): | |
result.append(render_post(post, users.get(post.author))) | |
# This would put all the posts in order (eventually) | |
for post in sweg.map.eventual(posts, result): | |
yield render_post(post, users.get(post.author)) | |
# Maybe sync now, this would block shittily and be SLOWER than normal code | |
for post in sweg.map.sync(posts): | |
result.append(render_post(post, users.get(post.author)) | |
return result | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment