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:

    This, our respectable daily life, on which the man of common sense, the Englishman of the world, stands so squarely, and on which our institutions are founded, is in fact the veriest illusion, and will vanish like the baseless fabric of a vision; but that faint glimmer of reality which sometimes illuminates the darkness of daylight for all men, reveals something more solid and enduring than adamant, which is in fact the cornerstone of the world.
    Henry David Thoreau (1817–1862)

    All the philosophy, therefore, in the world, and all the religion, which is nothing but a species of philosophy, will never be able to carry us beyond the usual course of experience, or give us measures of conduct and behaviour different from those which are furnished by reflections on common life. No new fact can ever be inferred from the religious hypothesis; no event foreseen or foretold; no reward or punishment expected or dreaded, beyond what is already known by practice and observation.
    David Hume (1711–1776)