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:

    Romance reading and writing might be seen ... as a collectively elaborated female ritual through which women explore the consequences of their common social condition as the appendages of men and attempt to imagine a more perfect state where all the needs they so intensely feel and accept as given would be adequately addressed.
    Janice A. Radway (b. 1949)

    Studio executives are intelligent, brutally overworked men and women who share one thing in common with baseball managers: they wake up every morning of the world with the knowledge that sooner or later they’re going to get fired.
    William Goldman (b. 1931)