-
Notifications
You must be signed in to change notification settings - Fork 71
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
Feature request: an equivalent to Lwt.npick
#558
Comments
Hi @SGrondin, thanks for the detailed issue. Something like this sounds useful to me, as you said, for that smaller amount of the time you might want to do something different in the case that both fibers succeed simultaneously. Without extending fibres to support this, I can't think of a solution that doesn't involve lifting into Eio promises so it seems like a good idea. It also reminds me a bit of |
Yes, something like this sounds useful. I'd been wondering about having an optional val first : ?combine:('a -> 'a -> 'a) -> (unit -> 'a) -> (unit -> 'a) -> 'a So if we get an additional value while waiting for things to cancel, it does Having a separate function and returning a list might be simpler, though. What are you planning to use it for? |
These are a few real world Eio examples where I've used
I like your idea! |
Addressed by #587 |
Motivation
Under
Fiber.first
:This enables
Fiber.first
to have a nice, convenient API. 98% of the time, I do not care about the edge case, so the benefits of the API are worth the downside explained in the warning.But 2% of the time, I do care about the return value of the second fiber that may also have succeeded.
Comparison: Lwt
Lwt.pick
This function is roughly equivalent to
Fiber.any
.Lwt.npick
Draft idea
We're optimizing for the 2% case here. Something that behaves just like
Fiber.first
, but without losing the second successful result (when it succeeds """at the same time""").The way Lwt accomplishes this is by scanning the list for other successful promises before resolving the returned promise.
I had a quick look at the code and it seems doable.
Is this a feature the maintainers would welcome?
The text was updated successfully, but these errors were encountered: