Created
July 8, 2014 16:34
-
-
Save dstufft/32a5348af06a7d622e64 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
import asyncio | |
def sync(coro): | |
if asyncio.iscoroutine(coro): | |
try: | |
next(coro) | |
except StopIteration as exc: | |
return exc.value | |
else: | |
return coro | |
@asyncio.coroutine | |
def asyncthing(): | |
return "foobar" | |
print(asyncthing()) | |
print(sync(asyncthing())) |
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
$ python p.py | |
<generator object coro at 0x101451b88> | |
foobar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment