Skip to content

Review what hand-written futures do when polled after completion #408

Closed

Description

@orthur2

Summary

In #394, removing Acquire::done means a completed Acquire acquires its permits again if it is polled. @tisonkun asked whether we should review the contract of the other hand-written futures, so I went through all 15 on main, Acquire included, and polled each public one twice.

Acquire::done is the only field among them that exists just for a poll after Ready. Once #394 removes it, every future except Condvar's wait, which panics, runs the same check on a second poll as on the first. It returns Ready again when the state it waited for can't go back, may wait again when it can (ManualResetEvent after a reset), and tries to take more when it takes something, such as a message or permits.

Most public waits are async fns, so a second poll panics with "async fn resumed after completion" and never reaches the hand-written future inside. Only three hand-written futures are public types:

Future Created by Second poll after Ready Documented
oneshot::Recv Receiver::into_future Ready(Err(Disconnected)) Must not be polled again
waitgroup::Wait WaitGroup::into_future Ready(()) No
shutdown::Shutdown shutdown::new Ready(()) No

The other 12 are private. Each is awaited once inside one of those async fns, except that the bounded broadcast sender polls its Acquire directly and replaces it once it completes, so nothing polls them after Ready today. I'd leave them as they are.

Questions

  1. Should waitgroup::Wait and Shutdown document that they return Ready again? Both stand for a state that never goes back, and they already behave this way, so this only makes it a promise. I'd do this.
  2. Should oneshot::Recv panic instead of returning Err(Disconnected)? After it returns a message, a second poll reports what looks like a dropped sender. The async fn waits panic instead, and so does Tokio's oneshot::Receiver (source). The channel ends at DISCONNECTED both after a received message and when the sender is dropped before sending, so Recv can't tell from the state whether it has already returned.

None of them implement FusedFuture, and I'd keep it that way. It would only cover these three types, futures::select! would still need .fuse() for the async fn waits, and it would add futures-core as our first required dependency.

Activity

  1. added a commit that references this issue on Nov 22, 2026
    0bb54c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions