Skip to content

Clarification needed on what happens when Future::poll wakes an old waker #119698

Open
@zopsicle

Description

@zopsicle

Location

https://doc.rust-lang.org/std/future/trait.Future.html#tymethod.poll

Summary

The documentation for Future::poll reads:

Note that on multiple calls to poll, only the Waker from the Context passed to the most recent call should be scheduled to receive a wakeup.

The implications of violating this aren’t specified. One might conclude that it is a bug to wake both the old and new wakers, as it says only the new one should be used. On the other hand, it says “should”, not “must”.

Note that there is no way to avoid waking both wakers in certain cases. See for instance the answer to In async Rust, how can a Future make sure it only calls the most recent Waker?, which reads:

This may cause the old waker to be woken unnecessarily, but that's fine.

I believe the intent of this requirement for poll is that there is no guarantee waking old wakers has any effect, but it is not a bug to wake them in addition to waking the most recent one. Is that correct? If so we may want to clarify this, preferably replacing the word “should” with something more concrete.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.I-async-nominatedNominated for discussion during an async working group meeting.T-libsRelevant to the library team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & await

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions