Expand description
Cooperative cancellation tokens for commands and tasks.
CancellationToken provides a thread-safe, cloneable signal that tasks
can poll to detect cooperative cancellation requests. It extends the
subscription StopSignal pattern to the command/task
domain, enabling bounded-lifetime effects and graceful teardown.
§Migration rationale
Web frameworks use AbortController / AbortSignal for effect cancellation.
This module provides an equivalent Rust-native primitive that the migration
code emitter can target when translating cancellable async workflows.
§Example
use ftui_runtime::cancellation::{CancellationSource, CancellationToken};
use std::time::Duration;
let source = CancellationSource::new();
let token = source.token();
// Pass token to a background task
std::thread::spawn(move || {
while !token.is_cancelled() {
// do work...
std::thread::sleep(Duration::from_millis(10));
}
});
// Cancel from the control side
source.cancel();Structs§
- Cancellation
Source - The control handle that triggers cancellation.
- Cancellation
Token - A thread-safe, cloneable cancellation token.