I have a object list that is processed using parallelstream. How can I migrate this to corroutine?
b
Big Chungus
01/04/2022, 7:04 PM
You need buffered channel with multiple consumer coroutines
Big Chungus
01/04/2022, 7:05 PM
In short:
• Parallel -> Channel
• Concurrent -> Flow
j
Joffrey
01/04/2022, 7:30 PM
It depends on the size of the collection you're processing, what you need to do with the elements. Do you have example code?
For instance, a parallel map for a collection that is not unreasonably large can be done this way (if the current dispatcher is multithreaded):
Copy code
val result = coroutineScope {
list.map {
async { tranformElement(it) }
}.awaitAll()
}