Created
August 21, 2012 00:58
-
-
Save dylanvee/3410107 to your computer and use it in GitHub Desktop.
tasklet control flow example
This file contains 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
# 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