File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/playground/flow/channels Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com.lukaslechner.coroutineusecasesonandroid.playground.flow.channels
2
+
3
+ import kotlinx.coroutines.channels.consumeEach
4
+ import kotlinx.coroutines.channels.produce
5
+ import kotlinx.coroutines.coroutineScope
6
+ import kotlinx.coroutines.launch
7
+
8
+ suspend fun main (): Unit = coroutineScope {
9
+
10
+ val channel = produce<Int > {
11
+ println (" Sending 10" )
12
+ send(10 )
13
+
14
+ println (" Sending 20" )
15
+ send(20 )
16
+ }
17
+
18
+ launch {
19
+ channel.consumeEach { receivedValue ->
20
+ println (" Consumer1: $receivedValue " )
21
+ }
22
+ }
23
+
24
+ launch {
25
+ channel.consumeEach { receivedValue ->
26
+ println (" Consumer2: $receivedValue " )
27
+ }
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments