altavir
04/26/2019, 11:25 AMFlow map operation parallelizable?gildor
04/26/2019, 11:38 AMgildor
04/26/2019, 11:38 AMaltavir
04/26/2019, 11:40 AMDeferred and then await them in next mapaltavir
04/26/2019, 11:47 AMfun <T,R> Flow<T>.mapParallel(scope: CoroutineScope, transform: suspend (T)->R) = map{
scope.async { transform(it) }
}.map{
it.await()
}altavir
04/26/2019, 11:58 AMgildor
04/26/2019, 3:02 PMI will need to create single-element flowsThere are extension functions for functional types (including suspend) which create flow from lambda/function
altavir
04/26/2019, 3:04 PMflatMapMerge does not provide control over scope and dispatcher, so it could give a work around at best. I think this is rather common task so it should have dedicated solution.elizarov
04/26/2019, 6:10 PM.flowWith(Dispatchers.Default) { // BG!
flatMapMerge {
flowOf(slowOperation(it))
}
}altavir
04/26/2019, 6:13 PMaltavir
04/26/2019, 6:29 PMaltavir
04/26/2019, 6:30 PMflowWith that skips channel generation in case context is the samealtavir
04/26/2019, 6:35 PMasync, store them and then await them. In my solution channel plays the role of interediate storage, but I do not think any solution with flowOn would generate this intermediate state because, channel there is consumed immediately.altavir
04/26/2019, 6:39 PMelizarov
04/26/2019, 6:57 PMsdeleuze
04/28/2019, 9:07 AMflatMap in the doc seems misleading to me, I think most people want parrallel execution when calling suspending function to transform element of a Flowsdeleuze
04/28/2019, 9:13 AMmap could do parrallel transformation when used with suspending functions?altavir
04/28/2019, 10:57 AMaltavir
04/28/2019, 11:11 AMgildor
04/28/2019, 3:19 PMmap parallel, even do this optional (add concurrency param with default value 1), so it will use fast path by default (current implementation) and optional easy to use concurrencysdeleuze
04/28/2019, 3:25 PMmap optional parameter, and I think I would go as far as using same concurency value that flatMap. Coroutines are cheap, Flow is designed to provide a powerful map operator where people will expect parrallel execution for suspending functions.sdeleuze
04/30/2019, 5:31 AM