1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-26 22:07:42 +02:00

Add oneshot::Sender::is_canceled() method

This commit is contained in:
Nikolay Kim
2019-12-11 20:52:57 +06:00
parent b28f32e82c
commit 52ecb4bcc5
2 changed files with 10 additions and 0 deletions

View File

@ -67,6 +67,12 @@ impl<T> Sender<T> {
Err(val)
}
}
/// Tests to see whether this `Sender`'s corresponding `Receiver`
/// has gone away.
pub fn is_canceled(&self) -> bool {
self.inner.strong_count() == 1
}
}
impl<T> Drop for Sender<T> {
@ -110,7 +116,9 @@ mod tests {
assert_eq!(rx.await.unwrap(), "test");
let (tx, rx) = channel();
assert!(!tx.is_canceled());
drop(rx);
assert!(tx.is_canceled());
assert!(tx.send("test").is_err());
let (tx, rx) = channel::<&'static str>();