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 notions that we find in credit around us and infused into our souls by our fathers’ seed, these seem to be the universal and natural ones. Whence it comes to pass that what is off the hinges of custom, people believe to be off the hinges of reason.”
    —Michel de Montaigne (1533–1592)

    “If common sense had been consulted, how many marriages would never have taken place; if uncommon or divine sense, how few marriages such as we witness would ever have taken place!”
    —Henry David Thoreau (1817–1862)