Created
January 22, 2012 16:30
-
-
Save mrjoes/1657598 to your computer and use it in GitHub Desktop.
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
# With a callback | |
def test(): | |
def handle_user(username, first_name, last_name, exception=None): | |
if exception: | |
# Blow up | |
return | |
print username, first_name, last_name | |
get_user_id(10, handle_user) | |
# With tornado.gen interface | |
@gen.async | |
def test2(): | |
username, first_name, last_name, exception = yield gen.Task(get_user_id, 10) | |
if exception: | |
# Blow up | |
return | |
print username, first_name, last_name | |
# User module | |
def get_user_id(user_id, callback): | |
async.run(da.read_user, callback, user_id) | |
# DA module | |
def read_user(user_id): | |
# Synchronous call here | |
user = User.objects.get(user_id) | |
if user is None: | |
raise Exception("Missing user") | |
return user.username, user.first_name, user.last_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment