Created
June 21, 2020 21:49
-
-
Save gabrielkirsten/4609163181169314fa72695919a15371 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import kotlinx.coroutines.* | |
import kotlin.system.* | |
fun main() = runBlocking { | |
val executionTime = measureTimeMillis { | |
val asyncTask1 = async{addTen(1)} | |
val asyncTask2 = async{addTen(2)} | |
println("task 1: ${asyncTask1.await()}") | |
println("task 2: ${asyncTask2.await()}") | |
} | |
println("execution time: [$executionTime] ms") | |
} | |
suspend fun addTen(n: Int): Int { | |
delay(1000) | |
return n + 10 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment