Skip to content

Commit

Permalink
Always expect Pending when polling the Notified
Browse files Browse the repository at this point in the history
Signed-off-by: Zahari Dichev <zaharidichev@gmail.com>
  • Loading branch information
zaharidichev committed Sep 24, 2020
1 parent 33888d6 commit 2ef49fa
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions tokio/src/sync/mpsc/chan.rs
Expand Up @@ -8,7 +8,7 @@ use crate::sync::Notify;

use std::fmt;
use std::process;
use std::sync::atomic::Ordering::{AcqRel, Relaxed, SeqCst};
use std::sync::atomic::Ordering::{AcqRel, Relaxed};
use std::task::Poll::{Pending, Ready};
use std::task::{Context, Poll};

Expand Down Expand Up @@ -223,19 +223,14 @@ where
let notified = self.inner.notify_rx_closed.notified();
pin!(notified);

// Polling this for first time will register the waiter and
// return `Pending` or return `Ready` right away. If `Ready`
// is returned we are done
let aquired_lost_notification =
crate::future::poll_fn(|cx| match Pin::new(&mut notified).poll(cx) {
Poll::Ready(()) => Poll::Ready(true),
Poll::Pending => Poll::Ready(false),
})
.await;

if aquired_lost_notification {
return;
}
// Polling the future once is guaranteed to return `Pending` as `watch`
// only notifies using `notify_waiters`.
crate::future::poll_fn(|cx| {
let res = Pin::new(&mut notified).poll(cx);
assert!(!res.is_ready());
Poll::Ready(())
})
.await;

if self.inner.semaphore.closed() {
return;
Expand Down

0 comments on commit 2ef49fa

Please sign in to comment.