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:
“Nature seems to have taken a particular Care to disseminate her Blessings among the different Regions of the World, with an Eye to this mutual Intercourse and Traffick among Mankind, that the Natives of the several Parts of the Globe might have a kind of Dependance [sic] upon one another, and be united together by their common Interest.”
—Joseph Addison (16721719)
“The black cat does not die. Those same books, if I am not mistaken, teach that the black cat is deathless. Deathless as evil. It is the origin of the common superstition of the cat with nine lives.”
—Peter Ruric, and Edgar G. Ulmer. Edgar G. Ulmer. Hjalmar Poelzig (Boris Karloff)