Skip to content

Commit d481598

Browse files
Add playground file for channels
1 parent 7c01501 commit d481598

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

0 commit comments

Comments
 (0)