Skip to content

Commit d7511e8

Browse files
Add playground file for StateFlow lecture
1 parent 5539a6d commit d7511e8

File tree

1 file changed

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

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.lukaslechner.coroutineusecasesonandroid.playground.flow.stateflow
2+
3+
import kotlinx.coroutines.coroutineScope
4+
import kotlinx.coroutines.flow.MutableStateFlow
5+
import kotlinx.coroutines.flow.update
6+
import kotlinx.coroutines.launch
7+
8+
suspend fun main() {
9+
10+
val counter = MutableStateFlow(0)
11+
12+
println(counter.value)
13+
14+
coroutineScope {
15+
repeat(10_000) {
16+
launch {
17+
counter.update { currentValue ->
18+
currentValue + 1
19+
}
20+
}
21+
}
22+
}
23+
24+
println(counter.value)
25+
}

0 commit comments

Comments
 (0)