Skip to content

Instantly share code, notes, and snippets.

@Jamesernator
Last active August 23, 2016 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jamesernator/d9e56bf2e8407a6ee6ea8b9f1c527ddb to your computer and use it in GitHub Desktop.
Save Jamesernator/d9e56bf2e8407a6ee6ea8b9f1c527ddb to your computer and use it in GitHub Desktop.
async def yieldfromexample():
RESULT = yield from EXPR
# Would become
async def yieldfromexample():
_i = aiter(EXPR)
try:
_y = await anext(_i)
except StopAsyncIteration as _e:
_r = _e.value
else:
while 1:
try:
_s = yield _y
except GeneratorExit as _e:
try:
_m = _i.aclose
except AttributeError:
pass
else:
await _m()
raise _e
except BaseException as _e:
_x = sys.exc_info()
try:
_m = _i.athrow
except AttributeError:
raise _e
else:
try:
_y = await _m(*_x)
except StopAsyncIteration as _e:
_r = _e.value
break
else:
try:
if _s is None:
_y = await anext(_i)
else:
_y = await _i.asend(_s)
except StopAsyncIteration as _e:
_r = _e.value
break
RESULT = _r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment