blob: 8a0944cbd1bf24e359ed42b6887c0e1c6e3f2a6b [file] [log] [blame]
Roman Elizarovb65dc7f2018-12-22 18:40:39 +03001import kotlinx.coroutines.*
2import kotlinx.coroutines.debug.*
3
4suspend fun computeValue(): String = coroutineScope {
5 val one = async { computeOne() }
6 val two = async { computeTwo() }
7 combineResults(one, two)
8}
9
10suspend fun combineResults(one: Deferred<String>, two: Deferred<String>): String =
11 one.await() + two.await()
12
13suspend fun computeOne(): String {
14 delay(5000)
15 return "4"
16}
17
18suspend fun computeTwo(): String {
19 delay(5000)
20 return "2"
21}
22
23fun main() = runBlocking {
24 DebugProbes.install()
25 val deferred = async { computeValue() }
26 // Delay for some time
27 delay(1000)
28 // Dump running coroutines
29 DebugProbes.dumpCoroutines()
30 println("\nDumping only deferred")
31 DebugProbes.printJob(deferred)
32}