Skip to content

Commit

Permalink
impl FusedFuture for oneshot::Receiver (rust-lang#2300)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jan 1, 2021
1 parent fc1d3df commit 7d9d80d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion futures-channel/src/oneshot.rs
Expand Up @@ -7,7 +7,7 @@ use core::fmt;
use core::pin::Pin;
use core::sync::atomic::AtomicBool;
use core::sync::atomic::Ordering::SeqCst;
use futures_core::future::Future;
use futures_core::future::{Future, FusedFuture};
use futures_core::task::{Context, Poll, Waker};

use crate::lock::Lock;
Expand Down Expand Up @@ -461,6 +461,21 @@ impl<T> Future for Receiver<T> {
}
}

impl<T> FusedFuture for Receiver<T> {
fn is_terminated(&self) -> bool {
if self.inner.complete.load(SeqCst) {
if let Some(slot) = self.inner.data.try_lock() {
if slot.is_some() {
return false;
}
}
true
} else {
false
}
}
}

impl<T> Drop for Receiver<T> {
fn drop(&mut self) {
self.inner.drop_rx()
Expand Down

0 comments on commit 7d9d80d

Please sign in to comment.