Common Uses
Coroutines are useful to implement the following:
- State machines within a single subroutine, where the state is determined by the current entry/exit point of the procedure; this can result in more readable code.
- Actor model of concurrency, for instance in video games. Each actor has its own procedures (this again logically separates the code), but they voluntarily give up control to central scheduler, which executes them sequentially (this is a form of cooperative multitasking).
- Generators, and these are useful for input/output and for generic traversal of data structures.
Read more about this topic: Coroutine
Famous quotes containing the word common:
“For we brought nothing into this world, and it is certain we can carry nothing out.”
—Bible: New Testament St. Paul, in 1 Timothy, 6:7.
The words also appear in the Book of Common Prayer, Burial of the Dead.
“No illusion is more crucial than the illusion that great success and huge money buy you immunity from the common ills of mankind, such as cars that wont start.”
—Larry McMurtry (b. 1936)