How are coroutines implemented in JVM langs without JVM support?

前端 未结 4 759
醉话见心
醉话见心 2020-12-23 13:28

This question came up after reading the Loom proposal, which describes an approach of implementing coroutines in the Java programming language.

Particularly this pro

4条回答
  •  滥情空心
    2020-12-23 14:15

    From the Kotlin Documentation on Coroutines (emphasis mine):

    Coroutines simplify asynchronous programming by putting the complications into libraries. The logic of the program can be expressed sequentially in a coroutine, and the underlying library will figure out the asynchrony for us. The library can wrap relevant parts of the user code into callbacks, subscribe to relevant events, schedule execution on different threads (or even different machines!), and the code remains as simple as if it was sequentially executed.

    Long story short, they are compiled down to code that uses callbacks and a state machine to handle suspending and resuming.

    Roman Elizarov, the project lead, gave two fantastic talks at KotlinConf 2017 on this subject. One is an Introduction to Coroutines, the second is a Deep Dive on Coroutines.

提交回复
热议问题