Skip to content

Instantly share code, notes, and snippets.

@b1naryth1ef
Created May 3, 2014 01:50
Show Gist options
  • Save b1naryth1ef/4a500457d8915973f4dc to your computer and use it in GitHub Desktop.
Save b1naryth1ef/4a500457d8915973f4dc to your computer and use it in GitHub Desktop.
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