Hi! I currently have this pipeline: `val input: F...
# coroutines
c
Hi! I currently have this pipeline:
Copy code
val input: Flow<MyObject> = ...
val output = input.map { it.toOtherObject() }
I would like the calls to
toOtherObject
to be ran in parallel, and I would like an exception in one call not to stop the others. I tried:
Copy code
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
val output = input.map {
  scope.async {
    it.toOtherObject()
  }
}.map { it.await() }
But this is still sequential, and not parallel. What am I doing wrong?
l
show how you are doing the collection
flows need a terminating operator
c
I'm joining multiple of such flows with
flatMapConcat
, and then `collect`ing the result.
I see, using
flatMapMerge
solves the concurrency issue, however it doesn't allow me to pass a
SupervisorScope
t
put a try/catch around the
toOtherObject
call? return null in the catch and later on mapNotNull?