-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sync:
oneshot::Receiver::{is_empty, is_closed}
this commit proposes two new methods for tokio's `sync::oneshot::Receiver<T>` type: `is_empty()` and `is_closed()`. these follow the same general pattern as existing `is_empty()` and `is_closed()` methods on other channels such as [`sync::mpsc::Sender::is_closed()`](https://docs.rs/tokio/latest/tokio/sync/mpsc/struct.Sender.html#method.is_closed), [`sync::mpsc::Receiver::is_closed()`](https://docs.rs/tokio/latest/tokio/sync/mpsc/struct.Receiver.html#method.is_closed), [`sync::oneshot::Receiver::is_closed()`](https://docs.rs/tokio/latest/tokio/sync/oneshot/struct.Sender.html#method.is_closed), [`sync::broadcast::Receiver::is_empty()`](https://docs.rs/tokio/latest/tokio/sync/broadcast/struct.Receiver.html#method.is_empty), [`sync::mpsc::Receiver::is_empty()`](https://docs.rs/tokio/latest/tokio/sync/mpsc/struct.Receiver.html#method.is_empty), ...and so forth. broadly speaking, users of the oneshot channel are encouraged to `.await` the `Receiver<T>` directly, as it will only yield a single value. users that are writing low-level code, implementing `Future`s directly, may instead poll the receiver via `<Receiver<T> as Future<Output = Result<T, RecvError>::poll(..)`. because (a) `poll()` has an `&mut self` receiver that does not take ownership in the same way as `.await`ing the receiver will, and (b) the contract of `std::future::Future` states that clients should not poll a future after it has yielded `Poll::Ready(value)`, users implementing `Future`s in terms of a oneshot channel do not have a way to inspect the state of a oneshot channel. this commit aims to provide such users means to passively inspect the state of a oneshot channel, to avoid violating the contact of `Future::poll(..)`, or requiring that a oneshot channel users track this state themselves externally.
- Loading branch information
Showing
2 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters