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:
“My facts shall be falsehoods to the common sense. I would so state facts that they shall be significant, shall be myths or mythologic. Facts which the mind perceived, thoughts which the body thoughtwith these I deal.”
—Henry David Thoreau (18171862)
“So didst thou travel on lifes common way,
In cheerful godliness; and yet thy heart
The lowliest duties on herself did lay.”
—William Wordsworth (17701850)