Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created April 4, 2020 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magdamiu/5e5b2d0d404a98acc0c6a14f6295659e to your computer and use it in GitHub Desktop.
Save magdamiu/5e5b2d0d404a98acc0c6a14f6295659e to your computer and use it in GitHub Desktop.
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