Provide an or! macro that handles any number of futures#7
Provide an or! macro that handles any number of futures#7joshtriplett wants to merge 2 commits intosmol-rs:masterfrom
or! macro that handles any number of futures#7Conversation
This has the same effect as f1.or(f2.or(f3.or(...))) but without the nesting.
ghost
left a comment
There was a problem hiding this comment.
This looks good, thank you!
I kind of wish the or! macro appeared in the future module rather than in the crate root. It might a bit tricky to achieve that though. What do you think?
|
@stjepang That's doable. Could you live with it appearing as both |
Fix the documentation accordingly, and ensure it shows up in both places. Rename the internal macro to a more internal name. Make the macro work without requiring the caller to import FutureExt.
|
Hmm, I would be okay with a helper crate, perhaps |
|
Alright, I can try that. (It'd look a lot like this, but with the macro implementations moved to that helper crate, and then |
|
Sounds good! |
|
I loved this so much I stole it for |
|
You could actually just depend on futures-micro to get this macro now it's released, instead of extracting it out into a new crate. You'd also get an implementation of |
|
That’s actually a good idea :) |
|
@jjl: I think the implementation of zip should pattern-match out of the nested 2-tuples, and emit an N-tuple. That isn't hard to do in a macro, and it would substantially improve usability. |
|
i completely agree, I just haven't gotten around to figuring it out yet. |
|
I would use this :) |
|
you already can, it's in the released |
|
I am using it, id be happy to see a reexport if that happens.
…On Wed, Aug 26, 2020 at 10:11 PM jjl ***@***.***> wrote:
you already can, it's in the released futures-micro
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#7 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADPI5BFTTU7ABAIZOUEV4TSCXTG7ANCNFSM4PU5A2ZA>
.
|
|
there's a PR for that! #15 |
|
Is there still any interest in this? Personally I'm a fan of the fact that |
I think such a chain is basically an anti-pattern because polling will become unfair. tokio-rs/tokio#2319 |
This has the same effect as f1.or(f2.or(f3.or(...))) but without the
nesting.
Note that an equivalent
race!macro would not be fair, since it wouldbe a coin-flip at each level. A fair
race!macro would need to countthe number of futures, and select randomly. This could be done by adding
a version of the
Racefuture that has a count and checks its firstfuture first with 1/N probability, and its second future first
otherwise.