Docs

Coroutines

Structured concurrency for Kotlin.

What is Coroutines

Coroutines let you write asynchronous code that reads like sequential code, using suspend functions.

Install

gradle
kotlin
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")

Usage

kotlin
kotlin
suspend fun load() = coroutineScope {
    val a = async { api.user() }
    val b = async { api.orders() }
    a.await() to b.await()
}

Docs

Official documentation: Coroutines.