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:
“God has given you your country as cradle, and humanity as mother; you cannot rightly love your brethren of the cradle if you love not the common mother.”
—Giuseppe Mazzini (18051872)
“There were none of the small deer up there; they are more common about the settlements. One ran into the city of Bangor two years before, and jumped through a window of costly plate glass, and then into a mirror, where it thought it recognized one of its kind.... This the inhabitants speak of as the deer that went a-shopping.”
—Henry David Thoreau (18171862)