Struct Notified
struct Notified<'a> { ... }
Future returned from [Notify::notified()].
This future is fused, so once it has completed, any future calls to poll
will immediately return Poll::Ready.
Implementations
impl Notified<'_>
fn enable(self: Pin<&mut Self>) -> boolAdds this future to the list of futures that are ready to receive wakeups from calls to
notify_one.Polling the future also adds it to the list, so this method should only be used if you want to add the future to the list before the first call to
poll. (In fact, this method is equivalent to callingpollexcept that noWakeris registered.)This has no effect on notifications sent using
notify_waiters, which are received as long as they happen after the creation of theNotifiedregardless of whetherenableorpollhas been called.This method returns true if the
Notifiedis ready. This happens in the following situations:- The
notify_waitersmethod was called between the creation of theNotifiedand the call to this method. - This is the first call to
enableorpollon this future, and theNotifywas holding a permit from a previous call tonotify_one. The call consumes the permit in that case. - The future has previously been enabled or polled, and it has since
then been marked ready by either consuming a permit from the
Notify, or by a call tonotify_oneornotify_waitersthat removed it from the list of futures ready to receive wakeups.
If this method returns true, any future calls to poll on the same future will immediately return
Poll::Ready.Examples
Unbound multi-producer multi-consumer (mpmc) channel.
The call to
enableis important because otherwise if you have two calls torecvand two calls tosendin parallel, the following could happen:- Both calls to
try_recvreturnNone. - Both new elements are added to the vector.
- The
notify_onemethod is called twice, adding only a single permit to theNotify. - Both calls to
recvreach theNotifiedfuture. One of them consumes the permit, and the other sleeps forever.
By adding the
Notifiedfutures to the list by callingenablebeforetry_recv, thenotify_onecalls in step three would remove the futures from the list and mark them notified instead of adding a permit to theNotify. This ensures that both futures are woken.use Notify; use VecDeque; use Mutex;- The
impl Drop for Notified<'_>
fn drop(self: &mut Self)
impl Future for Notified<'_>
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()>
impl<'a> Debug for Notified<'a>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<'a> Freeze for Notified<'a>
impl<'a> RefUnwindSafe for Notified<'a>
impl<'a> Send for Notified<'a>
impl<'a> Sync for Notified<'a>
impl<'a> Unpin for Notified<'a>
impl<'a> UnsafeUnpin for Notified<'a>
impl<'a> UnwindSafe for Notified<'a>
impl<F> IntoFuture for Notified<'a>
fn into_future(self: Self) -> <F as IntoFuture>::IntoFuture
impl<T> Any for Notified<'a>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Notified<'a>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Notified<'a>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for Notified<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for Notified<'a>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Notified<'a>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Notified<'a>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>