pub struct CancelToken { /* private fields */ }Expand description
Shared cancellation flag for tool execution.
A thin wrapper around Arc<AtomicBool>. Tools (bash, long-running shells)
poll [is_cancelled] at short intervals and abort when it becomes true;
the server flips the flag on Ctrl-C / cancel RPC.
Tools that complete in microseconds (read, write, edit) are free to ignore
the token entirely, or check it once at the top to return a cancelled
error if the user cancelled before execution began.
Clones share the same underlying atomic.
Implementations§
Source§impl CancelToken
impl CancelToken
Sourcepub fn from_flag(flag: Arc<AtomicBool>) -> Self
pub fn from_flag(flag: Arc<AtomicBool>) -> Self
Wrap an existing shared flag. Useful when the server already owns an
Arc<AtomicBool> (per-session cancel flag) and wants to expose it to
tool-execution paths without re-wrapping.
Sourcepub fn flag(&self) -> Arc<AtomicBool>
pub fn flag(&self) -> Arc<AtomicBool>
Return the underlying shared flag (same Arc).
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
True if the token has been cancelled.
Trait Implementations§
Source§impl Clone for CancelToken
impl Clone for CancelToken
Source§fn clone(&self) -> CancelToken
fn clone(&self) -> CancelToken
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CancelToken
impl Debug for CancelToken
Source§impl Default for CancelToken
impl Default for CancelToken
Source§fn default() -> CancelToken
fn default() -> CancelToken
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CancelToken
impl RefUnwindSafe for CancelToken
impl Send for CancelToken
impl Sync for CancelToken
impl Unpin for CancelToken
impl UnsafeUnpin for CancelToken
impl UnwindSafe for CancelToken
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