File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/playground/flow/concurrency Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments