Skip to main content

Module cancel

Module cancel 

Source
Expand description

Cooperative cancellation signal for agent loops.

CancelSignal wraps a tokio_util::sync::CancellationToken, which is purpose-built to avoid the time-of-check-to-time-of-use (TOCTOU) race that plagues hand-rolled AtomicBool + Notify combinations.

§Usage

use loopctl::cancel::CancelSignal;
use std::sync::Arc;

let signal = Arc::new(CancelSignal::new());
let signal_clone = signal.clone();

signal_clone.cancel();

tokio::select! {
    result = stream_next() => { /* ... */ }
    _ = signal.notified() => { /* cancelled! */ }
}

Structs§

CancelSignal
Shared cancellation signal backed by a tokio_util::sync::CancellationToken.