Closed kirill-gerasimenko-da closed 1 month ago
fork1
and fork2
are ForkIO
values. Each has two members: Cancel
and Await
. So, you can either let them run independently and let them finish in their own time, or Await
them like so:
public static IO<B> Apply<A, B>(this IO<Func<A, B>> ff, IO<A> fa) =>
from tf in ff.Fork()
from ta in fa.Fork()
from f in tf.Await
from a in ta.Await
select f(a);
I'll add an AwaitAll
at some point. It should be fairly easy to see how it would work.
Thanks!
Would it be easy to also add AwaitAny once you get there?
I'll add an
AwaitAll
at some point. It should be fairly easy to see how it would work.
This will be available in the next release.
Would it be easy to also add
AwaitAny
once you get there?
Hi!
I'm trying to figure out how to properly/idiomatically await all of the forked operations I start.
I have two
Eff<Unit>
which I fork and I would like to wait for both of them to finish. Both of these effects start background threads (I can't control that), which then call the callback I pass to them. These components lifetime is controlled via CancellationToken passed from the Eff's runtime (so they should stop and release the threads and all resources once CancellationToken passed via the environment is cancelled, at least I hope so).This is how I do it right now (some pieces copied from the examples, like infiniteLoop):
It works as I would expect, but I'm not confident that it's the correct way. I'd assume there could be something like
IO.AwaitAll(Seq<ForkIO> ioSeq)
or something like that that would have similar semantics withTask.WhenAll
for example.Is there already a way to have such semantics?
Thanks!