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:
“A country is strong which consists of wealthy families, every member of whom is interested in defending a common treasure; it is weak when composed of scattered individuals, to whom it matters little whether they obey seven or one, a Russian or a Corsican, so long as each keeps his own plot of land, blind in their wretched egotism, to the fact that the day is coming when this too will be torn from them.”
—HonorĂ© De Balzac (17991850)
“When we are high and airy hundreds say
That if we hold that flight theyll leave the place,
While those same hundreds mock another day
Because we have made our art of common things ...”
—William Butler Yeats (18651939)