pub struct Cancellation { /* private fields */ }Expand description
A runtime-independent, cooperative cancellation signal.
Clones share a persistent cancellation state. Child signals receive ancestor cancellation, but cancelling a child does not cancel its parent or siblings. Dropping a signal does not request cancellation. Signals neither own tasks nor abort futures; callers decide how to respond and separately await completion.
use base_scheduler::{Cancellation, Cancelled};
let system = Cancellation::new();
let server = system.child();
assert!(server.cancel());
assert_eq!(server.check(), Err(Cancelled));
assert!(!system.is_cancelled());
assert!(system.cancel());Implementations§
Source§impl Cancellation
impl Cancellation
Sourcepub const fn never() -> Self
pub const fn never() -> Self
Create a signal which cannot be cancelled and requires no allocation. cancel always returns false and cancelled remains pending forever.
Sourcepub const fn is_never(&self) -> bool
pub const fn is_never(&self) -> bool
Whether this signal can never be cancelled. This is true for Self::never and its clones; its children are independently cancellable. Backends can omit cancellation registration for these signals.
Sourcepub fn child(&self) -> Self
pub fn child(&self) -> Self
Create a signal cancelled by this signal or any of its ancestors. A child of an already-cancelled signal starts cancelled. A child of a never-cancelled signal is an independent, cancellable signal.
Sourcepub fn cancel(&self) -> bool
pub fn cancel(&self) -> bool
Request cancellation of this signal and all its descendants. Returns true only for the first request on this signal. Repeated requests never escalate. Waiters are woken after the entire family lock is released. Concurrent observers may see propagation in progress, but all descendants are cancelled when this call returns. This does not wait for their work.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Whether cancellation has been requested.
Sourcepub fn check(&self) -> Result<(), Cancelled>
pub fn check(&self) -> Result<(), Cancelled>
Check for cancellation at an explicit cooperative cancellation point.
Sourcepub async fn cancelled(&self)
pub async fn cancelled(&self)
Wait for cancellation using standard future polling and wakeups. This future is immediately ready if already cancelled. Dropping the wait unregisters its listener without cancelling the signal or other waiters. Listener storage is retained inline in the future, without a separate allocation.