October 2018
Intermediate to advanced
420 pages
10h 26m
English
Coroutines are another building block of AsyncIO. Coroutines were already covered in detail previously in this chapter. A coroutine is basically a generator with syntactic sugar. A coroutine is an asynchronous function that can be interrupted and resumed at specific locations. A coroutine is declared the same way as a function, but with the async keyword prefixed:
import datetimeasync def wait(delay): now = datetime.datetime.now() print("wait for {} seconds at {}:{}:{}".format( delay, now.hour, now.minute, now.second)) return True
This coroutine just returns True for now. The first big difference between a coroutine and a regular function is the fact that its code is not immediately executed when the coroutine is called. Instead, ...