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:
“This very Rome that we behold deserves our love ...: the only common and universal city.”
—Michel de Montaigne (15331592)
“The line of separation was very distinct, and the Indian immediately remarked, I guess you and I go there,I guess theres room for my canoe there. This was his common expression instead of saying we. He never addressed us by our names, though curious to know how they were spelled and what they meant, while we called him Polis. He had already guessed very accurately at our ages, and said that he was forty-eight.”
—Henry David Thoreau (18171862)