Skip to content

Commit 26b5efa

Browse files
Initial code for 'flows are cold' lecture
1 parent e3a4ce7 commit 26b5efa

File tree

1 file changed

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

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.lukaslechner.coroutineusecasesonandroid.playground.flow.hot_and_cold_flows
2+
3+
import kotlinx.coroutines.coroutineScope
4+
import kotlinx.coroutines.delay
5+
import kotlinx.coroutines.flow.flow
6+
import kotlinx.coroutines.flow.onEach
7+
8+
fun coldFlow() = flow {
9+
println("Emitting 1")
10+
emit(1)
11+
12+
println("Emitting 2")
13+
emit(2)
14+
15+
println("Emitting 3")
16+
emit(3)
17+
}.onEach {
18+
delay(1000)
19+
}
20+
21+
suspend fun main(): Unit = coroutineScope {
22+
23+
coldFlow()
24+
.collect {
25+
println("Collector 1 collects: $it")
26+
}
27+
}

0 commit comments

Comments
 (0)