Coroutines
Coroutines are an experimental feature of Kotlin that allow you to write asynchronous code sequentially. Their experimental nature means that this feature is still under development but that we can use it in production. The concept of coroutines is based on suspended computations that don't block a thread.
Coroutines in Kotlin are based on three things:
- Language-level support (the
suspend
keyword) - Low-level core API from the Kotlin standard library
- High-level API
Setting up a project
If you use the Maven build system, you should add the following line to the configuration
tag:
<arg>-Xcoroutines=enable</arg>
We need this because the coroutines feature has an experimental status now. The configuration tag will look as follows:
<configuration> <args> <arg>-Xcoroutines=enable</arg> </args> </configuration>
To add the kotlin-coroutines-core
library (https://github.com/Kotlin/kotlinx.coroutines/tree/master/core/kotlinx-coroutines...