I\'m writing a library that I\'d like end-users to be able to optionally use as if its methods and functions were not coroutines.
For example, given this function:>
You need two functions -- asynchronous coroutine and synchronous regular function:
@asyncio.coroutine
def async_gettter():
return (yield from http_client.get('http://example.com'))
def sync_getter()
return asyncio.get_event_loop().run_until_complete(async_getter())
magically_determine_if_being_yielded_from() is actually event_loop.is_running() but I strongly don't recommend to mix sync and async code in the same function.