Generator-based coroutines can be easily created from function object:
coro = asyncio.coroutine(func)
What about native coroutines (which usually creates by async def
)?
Is there any way to create them from existing function objects?
Generator-based coroutines can be easily created from function object:
coro = asyncio.coroutine(func)
What about native coroutines (which usually creates by async def
)?
Is there any way to create them from existing function objects?
In Python 3.5 the way to create an async function is by using the async def() syntax. Not sure of the benefit of trying to wrap a normal function into a native coroutine because if there is nothing to await, it would seem pointless? Especially since there is no need to call the function using await or yield from? (Since you can just execute it normally.)
Nevertheless, would this work for your purposes?
def test():
print('boo')
async def async_test():
return test()