Skip to content

Instantly share code, notes, and snippets.

@dylanvee
Created August 21, 2012 00:58
Show Gist options
  • Save dylanvee/3410107 to your computer and use it in GitHub Desktop.
Save dylanvee/3410107 to your computer and use it in GitHub Desktop.
tasklet control flow example
# from https://developers.google.com/appengine/docs/python/ndb/async
@ndb.tasklet
def get_cart_async(acct):
cart = yield CartItem.query(CartItem.account == acct.key).fetch_async()
yield ndb.get_multi_async([item.inventory for item in cart])
raise ndb.Return(cart)
@ndb.tasklet
def get_offers_async(acct):
offers = yield SpecialOffer.query().fetch_async(10)
yield ndb.get_multi_async([offer.inventory for offer in offers])
raise ndb.Return(offers)
@ndb.tasklet
def get_cart_plus_offers(acct):
cart, offers = yield get_cart_async(acct), get_offers_async(acct)
raise ndb.Return((cart, offers))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment