https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

Sam Garfinkel

05/28/2020, 3:39 PM
Is there a way to take say a sequence of
Foo
, run
Bar
on all of the `Foo`s in parallel, then rejoin the results of
Bar(Foo)
as an iterable of
Foo
in the original order they were given? Suppose
Bar(Foo)
will not run the same amount of time per
Foo
.
u

uli

05/29/2020, 3:34 PM
something like
Copy code
sequence
.map {
 async { Foo(Bar) }
}.map { 
 it.await() 
}
s

Sam Garfinkel

06/02/2020, 3:24 PM
I think you’d actually want to do async for all then call awaitAll on all of the deferreds, but not sure. I don’t actually know if
map
runs sequentially on all elements before yielding to the next function (in Java streams, I think it’s not well defined).
2 Views