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:
“There is a plain distinction to be made betwixt pleasure and happiness. For tho there can be no happiness without pleasureyet the converse of the proposition will not hold true.We are so made, that from the common gratifications of our appetites, and the impressions of a thousand objects, we snatch the one, like a transient gleam, without being suffered to taste the other.”
—Laurence Sterne (17131768)
“The mere fact of leaving ultimate social control in the hands of the people has not guaranteed that men will be able to conduct their lives as free men. Those societies where men know they are free are often democracies, but sometimes they have strong chiefs and kings. ... they have, however, one common characteristic: they are all alike in making certain freedoms common to all citizens, and inalienable.”
—Ruth Benedict (18871948)