From 4a6322ba343ff33501608ac2235f003b048f05d0 Mon Sep 17 00:00:00 2001 From: Emile Fugulin Date: Fri, 10 May 2024 12:43:54 -0400 Subject: [PATCH] Add alive method on arbiter --- actix-rt/CHANGES.md | 1 + actix-rt/src/arbiter.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/actix-rt/CHANGES.md b/actix-rt/CHANGES.md index 4aadc419..20784536 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 574fd6f1..192435d2 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).