Some APIs initiate long-running operations (such as network IO, file IO, CPU- or GPU-intensive work, etc) and require the caller to block until they complete. Coroutines provide a way to avoid blocking a thread and replace it with a cheaper and more controllable operation: suspension of a coroutine.
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.
Many asynchronous mechanisms available in other languages can be implemented as libraries using Kotlin coroutines. This includes
await from C# and ECMAScript, channels and
select from Go, and generators/
yield from C# and Python.
In this report, Roman Elizarov talks about Kotlin Corouties. Coroutines that are presented in Kotlin 1.1 in a massively redesigned form versus the original plan. This talk assumes familiarity with previous year's presentation (only a short overview is given) and focuses on challenges that were encountered during the implementation of the original vision on Kotlin coroutines.
Roman is tutor developer at JetBrains and ITMO university.