Kotlin Coroutines: Design and Implementation

被引:12
作者
Elizarov, Roman [1 ]
Belyaev, Mikhail [2 ]
Akhin, Marat [2 ]
Usmanov, Ilmir [3 ]
机构
[1] JetBrains, St Petersburg, Russia
[2] Peter Great St Petersburg Polytech Univ, JetBrains Res, St Petersburg, Russia
[3] JetBrains GmbH, Munich, Germany
来源
PROCEEDINGS OF THE 2021 ACM SIGPLAN INTERNATIONAL SYMPOSIUM ON NEW IDEAS, NEW PARADIGMS, AND REFLECTIONS ON PROGRAMMING AND SOFTWARE, ONWARD! 2021 | 2021年
关键词
Kotlin; asynchronous programming; coroutines; continuations; language design;
D O I
10.1145/3486607.3486751
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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.
引用
收藏
页码:68 / 84
页数:17
相关论文
共 60 条
[1]  
Akhin Mahat, 2020, Kotlin language specification: Kotlin/Core Version 1.9-rfc+0.1
[2]  
[Anonymous], 1997, The Definition of Standard ML
[3]  
Appel A.W., 1991, Compiling with Continuations
[4]  
Baker H. G. Jr., 1977, SIGPLAN Notices, V12, P55, DOI 10.1145/872734.806932
[5]  
Bartel Joe., 2011, The Computer Journal, P37
[6]  
Bateman Alan, 2020, Structured Concurrency
[7]  
Bezanson J, 2012, Arxiv, DOI [arXiv:1209.5145, DOI 10.48550/ARXIV.1209.5145]
[8]  
Birtwhistle G.M., 1979, Simula BEGIN
[9]   FLOW DIAGRAMS TURING MACHINES AND LANGUAGES WITH ONLY 2 FORMATION RULES [J].
BOHM, C ;
JACOPINI, G .
COMMUNICATIONS OF THE ACM, 1966, 9 (05) :366-&
[10]   Representing control in the presence of one-shot continuations [J].
Bruggeman, C ;
Waddell, O ;
Dybvig, RK .
ACM SIGPLAN NOTICES, 1996, 31 (05) :99-107