Comfy Cats Effect room. Ask questions. Rant about config file formats. Be nice!
par
, like parSequence
or parMapN
(implicit x: X)
to those functions that require par
F
later
Hey! I am not sure I understand how Concurrent.start
and Fiber
works.
I have multiple concurrent computations which should be started by trigger. Then I need to wait for the completion of all of the computations. I am running multiple fibers and use Deferred
for synchronization. I realized that after calling Deferred.complete
my fibers are processed sequential, but not parallel (as I expected).
I added explicit ContextShift.shift
after Deferred.get
in my fiber and now it works in parallel.
Here it is a gist - https://gist.github.com/13h3r2/1923169269db6732170c0058d8a869c1 Pay attention to line 26.
Few questions based on this gist:
Fiber
s, Deferred
or something else?Thanks
import cats.implicits._
import cats.effect.implicits._
val fa: IO[A]
val fb: IO[B]
val g: (A, B) => C
implicit val cs: ContextShift[IO] = ??? // could get via EC
val fc: IO[C] = (fa, fb).parMapN(g)
fibers.foldLeft(... _.join)
means you will join them in order