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 world is but a perennial movement. All things in it are in constant motion—the earth, the rocks of the Caucasus, the pyramids of Egypt—both with the common motion and with their own.
    Michel de Montaigne (1533–1592)

    People who are not in love fail to understand how an intelligent man can suffer because of a very ordinary woman. This is like being surprised that anyone should be stricken with cholera because of a creature so insignificant as the common bacillus.
    Marcel Proust (1871–1922)