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:

    “How like a prodigal doth nature seem,
    When thou, for all thy gold, so common art!
    Thou teachest me to deem
    More sacredly of every human heart,
    Since each reflects in joy its scanty gleam
    Of Heaven, and could some wondrous secret show,
    Did we but pay the love we owe,
    And with a child’s undoubting wisdom look
    On all these living pages of God’s book.”
    —James Russell Lowell (1819–1891)

    “There seems to be a common strain of miserliness in the American people when it comes to throwing away toothpaste tubes which have a little left in the bottom.”
    —Robert Benchley (1889–1945)