Created
April 4, 2020 20:11
-
-
Save magdamiu/5e5b2d0d404a98acc0c6a14f6295659e to your computer and use it in GitHub Desktop.
async/await
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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