Coroutine - Common Uses

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:

    The educated do not share a common body of information, but a common state of mind.
    Mason Cooley (b. 1927)

    There is all the poetry in the world in a name. It is a poem which the mass of men hear and read. What is poetry in the common sense, but a hearing of such jingling names? I want nothing better than a good word. The name of a thing may easily be more than the thing itself to me.
    Henry David Thoreau (1817–1862)