Skip to content

Commit 0143fdd

Browse files
committed
Actually discard notifications
1 parent d9b7c77 commit 0143fdd

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/future/blocking.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use Async;
22
use future::Future;
3-
use executor;
3+
use executor::{self, NotifyHandle};
44
use task_impl::ThreadNotify;
55

66
/// Provides thread-blocking operations on a future.
@@ -34,14 +34,12 @@ impl<T: Future> Blocking<T> {
3434
/// the inner future is not in a ready state.
3535
///
3636
/// This function will return immediately if the inner future is not ready.
37-
pub fn poll(&mut self) -> Option<Result<T::Item, T::Error>> {
38-
ThreadNotify::with_current(|notify| {
39-
match self.inner.poll_future_notify(notify, 0) {
40-
Ok(Async::NotReady) => None,
41-
Ok(Async::Ready(v)) => Some(Ok(v)),
42-
Err(e) => Some(Err(e)),
43-
}
44-
})
37+
pub fn try_take(&mut self) -> Option<Result<T::Item, T::Error>> {
38+
match self.inner.poll_future_notify(&NotifyHandle::noop(), 0) {
39+
Ok(Async::NotReady) => None,
40+
Ok(Async::Ready(v)) => Some(Ok(v)),
41+
Err(e) => Some(Err(e)),
42+
}
4543
}
4644

4745
/// Block the current thread until this future is resolved.

src/task_impl/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,19 @@ impl NotifyHandle {
615615
NotifyHandle { inner: inner }
616616
}
617617

618+
/// Return a no-op notify handle
619+
pub fn noop() -> NotifyHandle {
620+
struct Noop;
621+
622+
impl Notify for Noop {
623+
fn notify(&self, _id: usize) {}
624+
}
625+
626+
const NOOP: &'static Noop = &Noop;
627+
628+
NotifyHandle::from(NOOP)
629+
}
630+
618631
/// Invokes the underlying instance of `Notify` with the provided `id`.
619632
pub fn notify(&self, id: usize) {
620633
unsafe { (*self.inner).notify(id) }

0 commit comments

Comments
 (0)