jean
12/02/2025, 12:41 PMlaunchIn ? It can be set with scope.launch(dispatcher) { ... } but not with
someFlow
.onEach { ... }
.launchIn(scope) // <- I can't set a dispatcher here
I created this extension but I wonder if there’s a reason for not using it
fun <T> Flow<T>.launchIn(scope: CoroutineScope, coroutineDispatcher: CoroutineDispatcher): Job = scope.launch(coroutineDispatcher) {
collect()
}
// Usage
someFlow
.onEach { ... }
.launchIn(scope, dispatcher)Vilgot Fredenberg
12/02/2025, 1:08 PMflowOn exists (even though the use case is slightly different)Winson Chiu
12/02/2025, 2:42 PMlaunchIn(scope + dispatcher)jean
12/02/2025, 7:26 PM