What are use-cases for a coroutine?

前端 未结 7 1916
你的背包
你的背包 2021-01-30 12:46

The concept of a coroutine sounds very interesting, but I don\'t know, if it makes sense in a real productive environment? What are use-cases for coroutines, that can be solved

7条回答
  •  無奈伤痛
    2021-01-30 13:20

    Coroutines are useful to implement producer/consumer patterns.

    For example, Python introduced coroutines in a language feature called generators, which was intended to simplify the implementation of iterators.

    They can also be useful to implement cooperative multitasking, where each task is a coroutine that yields to a scheduler/reactor.

提交回复
热议问题