https://kotlinlang.org logo
#flow
Title
# flow
j

Justin Tullgren

01/21/2022, 4:27 PM
Hi. Am i understanding correctly that
Channel.receiveAsFlow
can process individual items in parallel by collectors? Or is it an internal "fan out". I just want to process a queue of emissions in parallel. Thanks!
Copy code
val flow = channel.receiveAsFlow()
repeat(5) {  launch { flow.collect { /*receive channel item in separate coroutine */ } } }
n

Nick Allen

01/23/2022, 12:20 AM
Your code snippet is basically equivalent to:
Copy code
repeat(5) {  launch { channel.consumeEach { /*receive channel item in separate coroutine */ } } }
Items are processed concurrently, not sequentially.
👍 1
s

Stylianos Gakis

01/24/2022, 11:32 AM
A nice playground to play around with this and see how it behaves. https://pl.kotl.in/uP1JO2xX8
j

Justin Tullgren

01/24/2022, 2:32 PM
thank you both. thats what i was hoping for.