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 common behavior of mankind is the system of reference by means of which we interpret an unknown language.
    Ludwig Wittgenstein (1889–1951)

    Freedom of men under government is to have a standing rule to live by, common to every one of that society, and made by the legislative power vested in it; a liberty to follow my own will in all things, when the rule prescribes not, and not to be subject to the inconstant, unknown, arbitrary will of another man.
    John Locke (1632–1704)