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:

    “A man of rare common sense and directness of speech, as of action; a transcendentalist above all, a man of ideas and principles,Mthat was what distinguished him.”
    —Henry David Thoreau (1817–1862)

    “Though there are wreck-masters appointed to look after valuable property which must be advertised, yet undoubtedly a great deal of value is secretly carried off. But are we not all wreckers contriving that some treasure may be washed up on our beach, that we may secure it, and do we not infer the habits of these Nauset and Barnegat wreckers, from the common modes of getting a living?”
    —Henry David Thoreau (1817–1862)