We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e3a4ce7 commit 26b5efaCopy full SHA for 26b5efa
app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/playground/flow/hot_and_cold_flows/1-flows_are_cold.kt
@@ -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