The following example from Python in a Nutshell sets x to 23 after a delay of a second and a half:
@asyncio.coroutine
def delayed_result(delay, result):
yield from asyncio.sleep(delay)
return result
loop = asyncio.get_event_loop()
x = loop.run_until_complete(delayed_result(1.5, 23))
I feel difficult to understand what yield from asyncio.sleep(delay) does.
From https://docs.python.org/3/library/asyncio-task.html#asyncio.sleep
Coroutine asyncio.sleep(delay, result=None, *, loop=None)Create a coroutine that completes after a given time (in seconds). If result is provided, it is produced to the caller when the coroutine completes.
So asyncio.sleep(delay) returns a coroutine object.
What does a coroutine object "completes" mean?
What values does yield from asyncio.sleep(delay) provide to the main program?
Thanks.