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:

    Human life in common is only made possible when a majority comes together which is stronger than any separate individual and which remains united against all separate individuals. The power of this community is then set up as “right” in opposition to the power of the individual, which is condemned as “brute force.”
    Sigmund Freud (1856–1939)

    It is with deep grief that I learn of the death of your kind and brave Father; and, especially, that it is affecting your young heart beyond what is common in such cases.
    Abraham Lincoln (1809–1865)