From 52ecb4bcc5b5c2f006c14a42ce855ec1dd81ff73 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 11 Dec 2019 20:52:57 +0600 Subject: [PATCH] Add oneshot::Sender::is_canceled() method --- actix-utils/CHANGES.md | 2 ++ actix-utils/src/oneshot.rs | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/actix-utils/CHANGES.md b/actix-utils/CHANGES.md index 3cc98d96..85e00989 100644 --- a/actix-utils/CHANGES.md +++ b/actix-utils/CHANGES.md @@ -4,6 +4,8 @@ * Allow to create `framed::Dispatcher` with custom `mpsc::Receiver` +* Add `oneshot::Sender::is_canceled()` method + ## [1.0.1] - 2019-12-11 * Optimize InOrder service diff --git a/actix-utils/src/oneshot.rs b/actix-utils/src/oneshot.rs index 72aa7a84..9ec5f218 100644 --- a/actix-utils/src/oneshot.rs +++ b/actix-utils/src/oneshot.rs @@ -67,6 +67,12 @@ impl Sender { 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 Drop for Sender { @@ -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>();