pub struct InterruptToken { /* private fields */ }Expand description
Async-safe cancellation token shared across all components of a run.
§Usage
let token = InterruptToken::new();
let child = token.clone();
// In the agent thread
if child.is_requested() {
// bail out
}
// In the UI thread on ESC
token.request();Implementations§
Source§impl InterruptToken
impl InterruptToken
Sourcepub fn request(&self)
pub fn request(&self)
Signal that the user wants to cancel the current operation.
This is cheap and idempotent — calling it multiple times is fine.
Sourcepub fn force_interrupt(&self)
pub fn force_interrupt(&self)
Force-interrupt the current operation.
In the Rust implementation this is identical to request() since we rely
on cooperative cancellation via the CancellationToken rather than
injecting async exceptions into threads (which is a CPython-specific trick).
Sourcepub fn request_background(&self)
pub fn request_background(&self)
Request that the current operation be moved to the background.
This cancels the CancellationToken to immediately interrupt any
in-flight async operation (LLM streaming, tool execution), but does
NOT set the hard interrupt flag. The react loop distinguishes
background from hard interrupt by checking is_background_requested().
Sourcepub fn is_background_requested(&self) -> bool
pub fn is_background_requested(&self) -> bool
Check whether backgrounding has been requested.
Sourcepub fn is_requested(&self) -> bool
pub fn is_requested(&self) -> bool
Check whether cancellation has been requested.
This is a cheap atomic load suitable for hot polling loops.
Sourcepub fn throw_if_requested(&self) -> Result<(), InterruptedError>
pub fn throw_if_requested(&self) -> Result<(), InterruptedError>
Return an error if cancellation was requested.
Sourcepub async fn cancelled(&self)
pub async fn cancelled(&self)
Wait until cancellation is requested.
This is the primary async integration point — select! against this alongside your actual work future.
Sourcepub fn cancellation_token(&self) -> &CancellationToken
pub fn cancellation_token(&self) -> &CancellationToken
Get the underlying tokio_util::sync::CancellationToken.
Useful when you need to pass a token to lower-level async code or create child tokens.
Sourcepub fn child_token(&self) -> CancellationToken
pub fn child_token(&self) -> CancellationToken
Create a child token that is cancelled when the parent is cancelled.
Sourcepub fn reset(&self)
pub fn reset(&self)
Clear the cancellation signal (use with care — mainly for token reuse across multiple agent runs).
Sourcepub fn should_interrupt(&self) -> bool
pub fn should_interrupt(&self) -> bool
Alias for is_requested() — TaskMonitor compatibility.
Sourcepub fn request_interrupt(&self)
pub fn request_interrupt(&self)
Alias for request() — TaskMonitor compatibility.
Trait Implementations§
Source§impl Clone for InterruptToken
impl Clone for InterruptToken
Source§fn clone(&self) -> InterruptToken
fn clone(&self) -> InterruptToken
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more