pub struct InterruptionDetector { /* private fields */ }Expand description
Tracks active turns and manages cancellation tokens.
Implementations§
Source§impl InterruptionDetector
impl InterruptionDetector
pub fn new() -> Self
Sourcepub async fn start_turn(&self, key: TurnKey) -> CancelToken
pub async fn start_turn(&self, key: TurnKey) -> CancelToken
Register a new turn for the given key.
If there is already an active turn for this key, it is cancelled first.
Returns the cancellation token for the new turn — the handler should
check token.is_cancelled() periodically.
Sourcepub async fn finish_turn(&self, key: &TurnKey)
pub async fn finish_turn(&self, key: &TurnKey)
Finish a turn (normal completion). Removes the token from tracking.
Sourcepub async fn has_active_turn(&self, key: &TurnKey) -> bool
pub async fn has_active_turn(&self, key: &TurnKey) -> bool
Check if a turn is currently active for the given key.
Sourcepub async fn active_count(&self) -> usize
pub async fn active_count(&self) -> usize
Get the number of active turns.
Sourcepub async fn cancel_all(&self)
pub async fn cancel_all(&self)
Cancel all active turns (e.g. on shutdown).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for InterruptionDetector
impl !RefUnwindSafe for InterruptionDetector
impl Send for InterruptionDetector
impl Sync for InterruptionDetector
impl Unpin for InterruptionDetector
impl UnsafeUnpin for InterruptionDetector
impl !UnwindSafe for InterruptionDetector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more