-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
clarify the semantics of core::task::Waker::wake() #93961
Comments
I don't think you can guarantee that. A simple counter example would be shutting down the (async) runtime after a |
The case of a vanishing runtime is outside the control of both the Future implementor and the runtime implementor, so I think we can carve that out of the discussion. The fact that futures can disappear at any moment does not make other guarantees worthless, like the one I’m after. Saying that this is a runtime concern is also not going to work, at least not with the path Rust async has chosen. Cooperative scheduling can only work well if there is an agreed upon mechanism for temporarily yielding the CPU to other tasks, and with the Rust API of Future/Context/Waker there is no other option but to register oneself for later wake-up and then returning |
(my emphasis) These two statements conflict. You can't just throw away part of the problem and still speak of always and unconditionally.
Could you please restate the guarantee you'll looking for? Including (very reasonable) assumptions such as the runtime is still running.
I'm not sure why this isn't going to work as a runtime concern? Could you elaborate?
Isn't that the agreed upon mechanism already? |
I think we’re in violent agreement here :-) And since you confirm the agreed upon mechanism, I’ll just open a PR where we can hammer out the precise wording. |
Related to #74335 |
document expectations for Waker::wake fixes rust-lang#93961 Opened PR for a discussion on the precise wording.
Based on reading e.g. the Tokio sources and knowledge passed down from async monks to novices, I assume that calling
cx.waker().wake_by_ref()
from the task that is currently being polled will ensure that the task is polled again soon, even if no external reason arises. However, this behaviour is not documented, at least not unambiguously — the documentation forcore::future::Future
only states that the waker provided by the context can be used to wake up the task, which may technically require the task to be “sleeping” for this to have an effect.If there is consensus that
wake_by_ref
will always and unconditionally ensure one further call topoll
, then we should document this expectation as part of the Future contract. Who agrees? Anyone against? Am I missing something?The text was updated successfully, but these errors were encountered: