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:
“You know, what I very well know, that I bought you. And I know, what perhaps you think I dont know, you are now selling yourselves to somebody else; and I know, what you do not know, that I am buying another borough. May Gods curse light upon you all: may your houses be as open and common to all Excise Officers as your wifes and daughters were to me, when I stood for your scoundrel corporation.”
—Anthony Henley (d. 1745)
“The most beautiful lives, to my mind, are those that conform to the common human pattern, with order, but without miracle and without eccentricity.”
—Michel de Montaigne (15331592)