Skip to content

Commit 1206553

Browse files
Add small example about how delay works
1 parent eab10bd commit 1206553

File tree

1 file changed

+27
-0
lines changed
  • app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/playground/fundamentals

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.lukaslechner.coroutineusecasesonandroid.playground.fundamentals
2+
3+
import android.os.Handler
4+
import android.os.Looper
5+
import kotlinx.coroutines.async
6+
import kotlinx.coroutines.joinAll
7+
import kotlinx.coroutines.runBlocking
8+
9+
fun main() = runBlocking {
10+
println("main starts")
11+
joinAll(
12+
async { delayDemonstration(1, 500) },
13+
async { delayDemonstration(2, 300) }
14+
)
15+
println("main ends")
16+
}
17+
18+
suspend fun delayDemonstration(number: Int, delay: Long) {
19+
println("Coroutine $number starts work")
20+
21+
// delay(delay)
22+
23+
Handler(Looper.getMainLooper())
24+
.postDelayed({
25+
println("Coroutine $number has finished")
26+
}, 500)
27+
}

0 commit comments

Comments
 (0)