forked from Kotlin/kotlinx.coroutines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample.kt
32 lines (27 loc) · 754 Bytes
/
Example.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import kotlinx.coroutines.*
import kotlinx.coroutines.debug.*
suspend fun computeValue(): String = coroutineScope {
val one = async { computeOne() }
val two = async { computeTwo() }
combineResults(one, two)
}
suspend fun combineResults(one: Deferred<String>, two: Deferred<String>): String =
one.await() + two.await()
suspend fun computeOne(): String {
delay(5000)
return "4"
}
suspend fun computeTwo(): String {
delay(5000)
return "2"
}
fun main() = runBlocking {
DebugProbes.install()
val deferred = async { computeValue() }
// Delay for some time
delay(1000)
// Dump running coroutines
DebugProbes.dumpCoroutines()
println("\nDumping only deferred")
DebugProbes.printJob(deferred)
}