python - what does `yield from asyncio.sleep(delay)` do? -


the following example python in nutshell sets x 23 after delay of second , half:

@asyncio.coroutine def delayed_result(delay, result):   yield asyncio.sleep(delay)   return result  loop = asyncio.get_event_loop() x = loop.run_until_complete(delayed_result(1.5, 23)) 

i feel difficult understand yield 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 coroutine completes after given time (in seconds). if result provided, produced caller when coroutine completes.

so asyncio.sleep(delay) returns coroutine object.

what coroutine object "completes" mean?

what values yield asyncio.sleep(delay) provide main program?

thanks.

yield from python3.4 syntax 3.5 await make more sense.

"completes" means task coroutine has finished.

in case want use async sleep can computer other tasks while sleep-task running, makes more sense if have other parallel tasks/coroutines running.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -