Is there a reason for not having the possibility t...
# coroutines
j
Is there a reason for not having the possibility to set a dispatcher when calling
launchIn
? It can be set with
scope.launch(dispatcher) { ... }
but not with
Copy code
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
Copy code
fun <T> Flow<T>.launchIn(scope: CoroutineScope, coroutineDispatcher: CoroutineDispatcher): Job = scope.launch(coroutineDispatcher) {
    collect()
}

// Usage
someFlow
    .onEach { ... }
    .launchIn(scope, dispatcher)
v
My guess would be because
flowOn
exists (even though the use case is slightly different)
w
You can just do
launchIn(scope + dispatcher)
☝🏻 1
👍🏻 1
☝️ 2
☝🏼 1
j
aha true, I keep forgetting they can be added. Thanks!