Skip to content

Commit 9ece193

Browse files
Prepare playground file for lecture 'Buffers in SharedFlows and StateFlows'
1 parent ffeec50 commit 9ece193

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.lukaslechner.coroutineusecasesonandroid.playground.flow.concurrency
2+
3+
import kotlinx.coroutines.coroutineScope
4+
import kotlinx.coroutines.delay
5+
import kotlinx.coroutines.flow.MutableSharedFlow
6+
import kotlinx.coroutines.launch
7+
import kotlin.system.measureTimeMillis
8+
9+
suspend fun main(): Unit = coroutineScope {
10+
11+
val flow = MutableSharedFlow<Int>()
12+
13+
// Collector 1
14+
launch {
15+
flow.collect {
16+
println("Collector 1 processes $it")
17+
}
18+
}
19+
20+
// Emitter
21+
launch {
22+
val timeToEmit = measureTimeMillis {
23+
repeat(5) {
24+
flow.emit(it)
25+
delay(10)
26+
}
27+
}
28+
println("Time to emit all values: $timeToEmit ms")
29+
}
30+
}

0 commit comments

Comments
 (0)