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:
“There comes Poe, with his raven, like Barnaby Rudge,
Three-fifths of him genius, and two-fifths sheer fudge.
Who talks like a book of iambs and pentameters,
In a way to make people of common sense damn metres,
Who has written some things quite the best of their kind,
But the heart somehow seems all squeezed out by the mind.”
—James Russell Lowell (18191891)
“You common cry of curs, whose breath I hate
As reek athrotten fens, whose loves I prize
As the dead carcasses of unburied men
That do corrupt my airI banish you!”
—William Shakespeare (15641616)