Skip to content

Instantly share code, notes, and snippets.

@brake
Created June 10, 2016 22:04
Show Gist options
  • Select an option

  • Save brake/dab502af724163292ee88e0cb5cac3f6 to your computer and use it in GitHub Desktop.

Select an option

Save brake/dab502af724163292ee88e0cb5cac3f6 to your computer and use it in GitHub Desktop.
Python decorator turning generator into coroutine
def coroutine(gen_fn):
"""Python decorator turning generator into coroutine"""
def inner(*args, **kwargs):
gen = gen_fn(*args, **kwargs)
gen.next()
return gen
return inner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment