June 2025
Intermediate to advanced
1093 pages
33h 24m
English
Coroutines are a way to run multiple functions quasi-parallel within a thread. A caller interrupts its current work by starting a coroutine. The coroutine then runs until it interrupts itself—cooperatively. The coroutine can produce an intermediate result and pass it to the caller. Later, the caller can decide that the coroutine should continue its work. And so it can go back and forth.
Figure 29.1 Functions only return; coroutines pause and resume.
There are various application patterns for coroutines. For example, you can implement a generator. The coroutine continuously generates values while the caller retrieves the ...
Read now
Unlock full access