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 Banquos issue have I filed my mind;
For them the gracious Duncan have I murdered;
Put rancors in the vessel of my peace
Only for them; and mine eternal jewel
Given to the common enemy of man,
To make them kings, the seeds of Banquo kings!”
—William Shakespeare (15641616)
“We early arrive at the great discovery that there is one mind common to all individual men: that what is individual is less than what is universal ... that error, vice and disease have their seat in the superficial or individual nature.”
—Ralph Waldo Emerson (18031882)