In this recipe, we are going to explore how to use the coroutines framework in order to schedule asynchronous, concurrent execution of tasks. We are going to learn both how to synchronize a sequence of short background tasks and how to run expensive, long-running ones at the same time. We will simulate the sushi rolls preparation process to discover how to schedule blocking and non-blocking tasks together.
Using coroutines for asynchronous, concurrent execution of tasks
Getting ready
The first step to start working with Kotlin Coroutines is to add the core framework dependency to the project:
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.3'
The preceding code declares the kotlinx-coroutines...