-
Notifications
You must be signed in to change notification settings - Fork 640
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: generalise Future to accept parameter to poll()
#316
Comments
This corresponds to returning values from |
I think this is a really useful idea. It would be nice to be able to share state between futures without having to worry about panics due to improper borrowing. I think this would result in |
I believe this is a dupe of #129, so closing in favor of that. |
@alexcrichton This is different from #129 #129 Is about passing the This issue is a feature suggestion, which is independent of that issue: generalising the Futures would be interchangeable with this trait when the associated type is unit/empty tuple. |
Ok |
I don't think this being worth the breaking change for the following reasons:
As such, if somebody cares about this, I would suggest experimenting in another crate and reporting back. |
It would be useful for sharing a |
my case for the use caseNot being able to do this is pretty limiting for futures. It means that a single piece of data cannot own multiple sockets. The multiple sockets have to own that single data and we know how rust likes data having multiple owners. I can see how that works for a server, but it doesn't seem to fit the case of a client that is using heterogeneous IO with incompatible future types that are started at different times. This is a pretty common scenario. RefCell is a work-around, but then we're giving up all the compile time checks that make Rust so great and we're practically back to checking for null pointers like troglodytes. Please correct me if I'm wrong, I would love to be, but I've been working with it for a while and just don't see the way to do it without violating borrowing and ownership checks. as for interfaceIn my scenario, the shared state is global for the |
I think this was fixed in 0.3 (std::future::Future). |
Yeah, this is now out of |
An executor may wish to pass state into a future each time it is polled. This allows the implementation to exploit the fact that only one future at a time is running on the executor, by having the executor pass in a mutable borrow to some shared state.
This new trait would have all of the same combinators as Future, but would have an extra type parameter determining the type of the state passed to its
poll
method.Currently the workarounds are to either use an
Rc<RefCell<T>>
bound to each future, or a scoped thread-local value, both of which introduce unnecessary overhead.Another possible extension would be to allow returning data from
poll()
in theNotReady
case, but I don't have a use-case for that.Somewhat related to #129
The text was updated successfully, but these errors were encountered: