July 2018
Intermediate to advanced
242 pages
8h 6m
English
The first step to start working with Kotlin Coroutines is to add a core framework dependency to the project:
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.3'
The preceding code declares the kotlinx-coroutines-core dependency in a Gradle build script, which is used in the sample project (https://github.com/PacktPublishing/Kotlin-Standard-Library-Cookbook).
In the current recipe, we are going to make use of the following two functions:
private suspend fun `calculate the answer to life the universe and everything`(): Int { delay(5000) return 42}private suspend fun `show progress animation`() { val progressBarLength = 30 var currentPosition = 0 while (true) { print("\r") val progressbar = (0 until progressBarLength) ...
Read now
Unlock full access