https://kotlinlang.org logo
Title
d

dave08

09/17/2019, 3:22 PM
Is the only way to make a step in a flow concurrent by using flatMapMerge? I have a transform step that can be made concurrent (it uses network requests), can I just use a withContext on it?
d

Dennis Schröder

09/17/2019, 3:27 PM
If I understand your querstion right, my answer is: There is a async-version of
flow::map
flow::filter
flow::onEach
flow::transform
and others ... https://kotlinlang.org/docs/reference/coroutines/flow.html#terminal-flow-operators
d

dave08

09/17/2019, 3:47 PM
The only one of those that has a
concurrency
parameter is
flatMapMerge
... which I think collects each flow it receives in another coroutine... but I was wondering if I could avoid that... I think this question was asked before a few times... there might have been some updates since though...?
Maybe this helps you
.flowOn(Dispatchers.Default)
d

dave08

09/17/2019, 3:56 PM
That seems to create only one coroutine running on one other thread for the whole chain of operations before the collect. Whereas to have EACH one of the transforms run on a different coroutine, it wouldn't be sufficient as far as I understand...
d

Dennis Schröder

09/18/2019, 11:00 AM
d

dave08

09/18/2019, 12:17 PM
Thanks for reminding me about that article 🙂 ...