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>();