diff --git a/actix-rt/CHANGES.md b/actix-rt/CHANGES.md index 4aadc419a..207845366 100644 --- a/actix-rt/CHANGES.md +++ b/actix-rt/CHANGES.md @@ -3,6 +3,7 @@ ## Unreleased - Add `actix_rt::ArbiterBuilder` to allow user to configure the thread spawned for the arbiter. +- Add `Arbiter::alive` and `ArbiterHandle::alive` to check is the arbiter is still alive. ## 2.10.0 diff --git a/actix-rt/src/arbiter.rs b/actix-rt/src/arbiter.rs index 574fd6f10..192435d2f 100644 --- a/actix-rt/src/arbiter.rs +++ b/actix-rt/src/arbiter.rs @@ -71,6 +71,13 @@ impl ArbiterHandle { self.spawn(async { f() }) } + /// Check if the [Arbiter] is still alive. + /// + /// Returns false if the [Arbiter] has been dropped, returns true otherwise. + pub fn alive(&self) -> bool { + !self.tx.is_closed() + } + /// Instruct [Arbiter] to stop processing it's event loop. /// /// Returns true if stop message was sent successfully and false if the [Arbiter] has @@ -367,6 +374,13 @@ impl Arbiter { self.spawn(async { f() }) } + /// Check if the [Arbiter] is still alive. + /// + /// Returns false if the [Arbiter] has been dropped, returns true otherwise. + pub fn alive(&self) -> bool { + !self.tx.is_closed() + } + /// Wait for Arbiter's event loop to complete. /// /// Joins the underlying OS thread handle. See [`JoinHandle::join`](thread::JoinHandle::join).