In addition to the threading model provided by Java, Kotlin also introduces a coroutines model. Coroutines might be considered lightweight threads, and we’ll see what advantages they provide over an existing model of threads shortly.
The first thing you need to know is that coroutines are not part of the language. They are simply another library provided by JetBrains. For that reason, if we want to use them, we need to specify so in our Gradle configuration file, build.gradle:
dependencies {
...
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.21"
...
}
As of Kotlin 1.2, coroutines are still considered experimental. This doesn't mean that they don't work well, though, as some might think. It only means that some parts of the API may still change in the next versions.
What could change? For example, in 0.18, an Actor, which...