Repository navigation
Description
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
- Should
waitgroup::WaitandShutdowndocument that they returnReadyagain? 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. - Should
oneshot::Recvpanic instead of returningErr(Disconnected)? After it returns a message, a second poll reports what looks like a dropped sender. Theasync fnwaits panic instead, and so does Tokio'soneshot::Receiver(source). The channel ends atDISCONNECTEDboth after a received message and when the sender is dropped before sending, soRecvcan'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
docs: clarify post-completion polling contracts for hand-written futures