Structured concurrency

Asynchronous operations

fun requestSomeData() {
launch(UI) {
updateUI(performRequest())
}
}
fun requestSomeData() {
launch {
updateUI(performRequest())
}
}

Parallel decomposition

suspend fun loadAndCombine(name1: String, name2: String): Image { 
val deferred1 = async { loadImage(name1) }
val
deferred2 = async { loadImage(name2) }
return
combineImages(deferred1.await(), deferred2.await())
}
suspend fun loadAndCombine(name1: String, name2: String): Image =
coroutineScope {
val deferred1 = async { loadImage(name1) }
val
deferred2 = async { loadImage(name2) }
combineImages(deferred1.await(), deferred2.await())
}

Further reading

--

--

--

Project Lead for the Kotlin Programming Language @JetBrains

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The road to automating our Alexa Skills deployments

CRYPTO POWER X MOGWAR AMA RECAP

GitHub version number for multi-language package — Golang example

Separation of Concerns

Alibaba Cloud Object Storage vs. IBM Cloud and Oracle Cloud Equivalent

A Guide on How to Install Office 365 ProPlus on a Remote Desktop Services Server

How to Build a Nested Form in Rails using Fields_For

Software Quality Factors

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Roman Elizarov

Roman Elizarov

Project Lead for the Kotlin Programming Language @JetBrains

More from Medium

Kotlin Coroutines vs Java Virtual Threads — A good story, but just that…

Crash course on the Kotlin compiler | 1. Frontend: Parsing phase

Pictured above is a diagram of the frontend portion of the Kotlin compiler. A Kotlin file is fed into the compiler, which is then analyzed and broken down into AST/PSI so that it can be further analyzed in the resolution for correctness.

Object equality in Java and Kotlin

Async Jersey + Kotlin Coroutines