Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
async/await
fun add(a: Int, b: Int): Int {
return a + b
}
fun main() {
runBlocking {
println("Start main")
val sumOf2 = async {
println("Start sumOf2")
add(2, 2)
}
val sumOf3 = async {
println("Start sumOf3")
add(3, 3)
}
println("Awaiting the sums")
val total = sumOf2.await() + sumOf3.await()
println("Total is $total")
println("End main")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment