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:

    “We must return optimism to our parenting. To focus on the joys, not the hassles; the love, not the disappointments; the common sense, not the complexities.”
    —Fred G. Gosman (20th century)

    “The line of separation was very distinct, and the Indian immediately remarked, “I guess you and I go there,—I guess there’s room for my canoe there.” This was his common expression instead of saying “we.” He never addressed us by our names, though curious to know how they were spelled and what they meant, while we called him Polis. He had already guessed very accurately at our ages, and said that he was forty-eight.”
    —Henry David Thoreau (1817–1862)