Skip to content

Instantly share code, notes, and snippets.

@njsmith
Last active May 17, 2019 03:13
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 njsmith/74adef4a863b335eabdbb02569a9da30 to your computer and use it in GitHub Desktop.
Save njsmith/74adef4a863b335eabdbb02569a9da30 to your computer and use it in GitHub Desktop.
# https://gitter.im/python-trio/general?at=5cddee9a6366992a94ce41c5
@asynccontextmanager
async def generalized_move_on_after():
async with trio.open_nursery() as nursery:
async def arbitrary_event():
await wait_for_some_arbitrary_event()
nursery.cancel_scope.cancel()
nursery.start_soon(arbitrary_event)
yield nursery.cancel_scope
nursery.cancel_scope.cancel()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment