Kotlin coroutines: design and implementation
- 17 October 2021
- conference paper
- conference paper
- Published by Association for Computing Machinery (ACM) in Proceedings of the 2021 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software
Abstract
Asynchronous programming is having its “renaissance” moment in recent years. Created in the 1980s, it was in use for quite some time, but with the advent of multi-core processors, it has been sidestepped by multi-threaded programming, which was (for a long time) the de facto standard of performing concurrent computations. However, since the 2000s, more and more programming languages have begun to include the support for asynchronous programming, some built around asynchronicity from the start, others including it later in their evolution. In this paper, we explore the design and implementation of asynchronous programming in Kotlin, a multiplatform programming language from JetBrains, which uses coroutines for asynchronicity. Kotlin provides a compact built-in API for coroutine support, thus giving a lot of implementation freedom to the developer; this flexibility allows to transparently support different flavours of asynchronous programming within the same language. We overview existing approaches to asynchronous programming, zoom in and talk about coroutines in detail, and describe how they are used in Kotlin as the basis for asynchronous computations. Along the way, we show the flexibility of Kotlin coroutines, highlight several existing problems with asynchronicity, how they are fixed or worked-around in Kotlin, and also mention future directions asynchronous programming might explore.Keywords
This publication has 22 references indexed in Scilit:
- Implementing first-class polymorphic delimited continuations by a type-directed selective CPS-transformACM SIGPLAN Notices, 2009
- Revisiting coroutinesACM Transactions on Programming Languages and Systems, 2009
- A poor man's concurrency monadJournal of Functional Programming, 1999
- Representing control in the presence of one-shot continuationsACM SIGPLAN Notices, 1996
- The discoveries of continuationsHigher-Order and Symbolic Computation, 1993
- CMLACM SIGPLAN Notices, 1991
- MultithreadingACM SIGARCH Computer Architecture News, 1991
- Promises: linguistic support for efficient asynchronous procedure calls in distributed systemsACM SIGPLAN Notices, 1988
- The incremental garbage collection of processesACM SIGART Bulletin, 1977
- Flow diagrams, turing machines and languages with only two formation rulesCommunications of the ACM, 1966