Last active
June 7, 2020 16:46
-
-
Save ttamg/32bd451ed3e41e4552e93bf3172731fc to your computer and use it in GitHub Desktop.
Simple usage example for unsync
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
import time | |
from unsync import unsync | |
@unsync | |
def my_function(): | |
""" A function which we want to use asynchronously """ | |
time.sleep(1) | |
return "something fascinating" | |
# Calling the decorated function starts the coroutine running | |
thing = my_function() | |
# Note that it returns an unsync Unfuture object, NOT the return value (yet) | |
print(thing) | |
-> <unsync.unsync.Unfuture object at 0x106f87b90> | |
# To await the coroutine finishing and get the final return value, | |
# call the .result() method on this Unfuture object | |
print(thing.result()) | |
-> something fascinating |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment