Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add awaitAll and awaitAny that work with ForkIO #1440

Open
louthy opened this issue Jan 21, 2025 · 0 comments
Open

Add awaitAll and awaitAny that work with ForkIO #1440

louthy opened this issue Jan 21, 2025 · 0 comments
Assignees
Labels
enhancement v5 Related to version 5.0.0+

Comments

@louthy
Copy link
Owner

louthy commented Jan 21, 2025

The existing IO.awaitAll and IO.awaitAny all work with either IO<ForkIO<A>> or K<M, ForkIO<A>>. So, this works:

IO<A> op = ...;
var fa = op.Fork();
var fb = op.Fork();
var fc = op.Fork();
var result = IO.awaitAll(fa, fb, fc);

But, this doesn't:

var result = from fa in op.Fork()
             from fb in op.Fork()
             from fc in op.Fork()
             from _  in awaitAll(fa, fb, fc)
             select unit;

So, we need awaitAll and awaitAny that take raw ForkIO values, not just IO<ForkIO<A>> values.

awaitAll workaround

Use the .Await property of the ForkIO an then monad-chain the forks:

var result = from fa in op.Fork()
             from fb in op.Fork()
             from fc in op.Fork()
             from _  in fa.Await >> fb.Await >> fc.Await
             select unit;

That will wait for fa, fb, and fc to complete before continuing.

@louthy louthy added enhancement v5 Related to version 5.0.0+ labels Jan 21, 2025
@louthy louthy self-assigned this Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement v5 Related to version 5.0.0+
Projects
None yet
Development

No branches or pull requests

1 participant