Skip to content

Commit 88bd185

Browse files
authored
impl FusedFuture for oneshot::Receiver (#2300)
1 parent caea9b1 commit 88bd185

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

futures-channel/src/oneshot.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::fmt;
77
use core::pin::Pin;
88
use core::sync::atomic::AtomicBool;
99
use core::sync::atomic::Ordering::SeqCst;
10-
use futures_core::future::Future;
10+
use futures_core::future::{Future, FusedFuture};
1111
use futures_core::task::{Context, Poll, Waker};
1212

1313
use crate::lock::Lock;
@@ -461,6 +461,21 @@ impl<T> Future for Receiver<T> {
461461
}
462462
}
463463

464+
impl<T> FusedFuture for Receiver<T> {
465+
fn is_terminated(&self) -> bool {
466+
if self.inner.complete.load(SeqCst) {
467+
if let Some(slot) = self.inner.data.try_lock() {
468+
if slot.is_some() {
469+
return false;
470+
}
471+
}
472+
true
473+
} else {
474+
false
475+
}
476+
}
477+
}
478+
464479
impl<T> Drop for Receiver<T> {
465480
fn drop(&mut self) {
466481
self.inner.drop_rx()

0 commit comments

Comments
 (0)