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:
“The desire to serve the common good must without fail be a requisite of the soul, a necessity for personal happiness; if it issues not from there, but from theoretical or other considerations, it is not at all the same thing.”
—Anton Pavlovich Chekhov (18601904)
“Unpretending mediocrity is good, and genius is glorious; but a weak flavor of genius in an essentially common person is detestable. It spoils the grand neutrality of a commonplace character, as the rinsings of an unwashed wine-glass spoil a draught of fair water.”
—Oliver Wendell Holmes, Sr. (18091894)