-
Notifications
You must be signed in to change notification settings - Fork 21
Add more helpers for Future
#594
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
Comments
std::future::Future
traitstd::future::Future
trait and add FusedFuture
std::future::Future
trait and add FusedFuture
std::future::Future
trait and FusedFuture
I would recommend reading past discussions on this (e.g., rust-lang/rust#111347). There have been several people who have suggested such a thing in the past, but none of them were accepted because of several unresolved questions. |
Except for what already pointed out in the past discussion I linked above, the things I was wondering about are:
|
Note that with supertrait item shadowing v2 at least the name overloading should become less problematic. |
std::future::Future
trait and FusedFuture
Future
Thanks, I've made some changes:
I think it might still be useful for manually wrapping multiple future, i.e. join in a specific order, with While most
I think other methods of
|
there's a WIP language feature to allow calling |
Thanks, removed the function |
cc @rust-lang/wg-async |
This really needs to be split up into several proposals.
Tokio explicitly decided to go away from
Why?
Why use a method over a macro? I think that macro syntax is nicer to read: let (res1, res2) = join!(fut1, fut2).await; vs let (res1, res2) = (fut1, fut2).join().await; I mean maybe I could be convinced otherwise, but like the other proposals here, I would like to see alternatives mentioned, and I would like to see a reason for why one approach is chosen over the alternatives. |
The problem is, as I said in the linked comment, that it cannot be correctly implemented without specializations. (Using specialization in std is not enough to do things correctly.) Even if the std/compiler can optimize it, it will only leave something broken unless the implementation on which the optimization depends is correctly implemented. |
Suppose you have a function taking an array of arbitrary, using fn f<Fut: Future<Output = ()>, const N: usize>(futures: [Fut; N]) {
join!(/* ? */);
} And using Having a [fut1, fut2].join().await;
(fut1, fut2).join().await; The problem I just realized though is
Thanks, so it'd require
I think |
If we adding a helper for such case, I think it is preferable that this be an explicit method rather than a From implementation. But I'm not sure that is really necessary, and also note that now_or_never uses noop_context so it does not work just using it. |
That's true, I've removed the From impl from proposal |
Uh oh!
There was an error while loading. Please reload this page.
Proposal
Problem statement
I propose to add more helpers to the
std::future::Future
trait to make it easier to use for async code.Motivating examples or use cases
futures_util::FutureExt
is widely used in async code as the stdlib does not provide the helper functions needed for many async crate.std::iter::Iterator
on the other hand, has lots of helper functions and thus most crates don't need to pull in any extra dependencies to use it, as compared toFuture
.Solution sketch
I propose to add the following provided trait methods, similar to how
Iterator
works to enable simple usage and ability to override for better/more efficient implementation:And join for array/tuple
The text was updated successfully, but these errors were encountered: