I look for an easy solution how I can consume a `channel` or `flow` in parallel. I don't really fin...
s
I look for an easy solution how I can consume a
channel
or
flow
in parallel. I don't really find something here, just a discussion on GitHub: https://github.com/Kotlin/kotlinx.coroutines/issues/172 I understood that
flow.buffer(3).collect { action() }
doesn't do that. What I want is receive N (N = cpu cores) entries from a collection in parallel to process them. I don't like how channel.receive() waits forever or throws an exception. What would be a simple solution for that?
1
s
In Arrow we have
Flow#parMap
or
Flow#parMapUnordered
. The implementations are relatively simple if you don't want to depend on the full library. https://github.com/arrow-kt/arrow/blob/18b946e8cb683c94b8cde4b39086a096a0139fb8/ar[…]fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/flow.kt
🙏 1
👍 3
😍 1
c
that looks cool!
s
And is also works great! That's exactly what I was looking for. Thank you! I will copy the function and mention arrow in my apps third party libraries 🙂
❤️ 1