Skip to content

Commit 4a6322b

Browse files
committed
Add alive method on arbiter
1 parent 943ddcd commit 4a6322b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

actix-rt/CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Add `actix_rt::ArbiterBuilder` to allow user to configure the thread spawned for the arbiter.
6+
- Add `Arbiter::alive` and `ArbiterHandle::alive` to check is the arbiter is still alive.
67

78
## 2.10.0
89

actix-rt/src/arbiter.rs

+14
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ impl ArbiterHandle {
7171
self.spawn(async { f() })
7272
}
7373

74+
/// Check if the [Arbiter] is still alive.
75+
///
76+
/// Returns false if the [Arbiter] has been dropped, returns true otherwise.
77+
pub fn alive(&self) -> bool {
78+
!self.tx.is_closed()
79+
}
80+
7481
/// Instruct [Arbiter] to stop processing it's event loop.
7582
///
7683
/// Returns true if stop message was sent successfully and false if the [Arbiter] has
@@ -367,6 +374,13 @@ impl Arbiter {
367374
self.spawn(async { f() })
368375
}
369376

377+
/// Check if the [Arbiter] is still alive.
378+
///
379+
/// Returns false if the [Arbiter] has been dropped, returns true otherwise.
380+
pub fn alive(&self) -> bool {
381+
!self.tx.is_closed()
382+
}
383+
370384
/// Wait for Arbiter's event loop to complete.
371385
///
372386
/// Joins the underlying OS thread handle. See [`JoinHandle::join`](thread::JoinHandle::join).

0 commit comments

Comments
 (0)