Skip to content

Instantly share code, notes, and snippets.

@gabrielkirsten
Created June 21, 2020 21:49
Show Gist options
  • Save gabrielkirsten/4609163181169314fa72695919a15371 to your computer and use it in GitHub Desktop.
Save gabrielkirsten/4609163181169314fa72695919a15371 to your computer and use it in GitHub Desktop.
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