pub struct TurnCancellation { /* private fields */ }Expand description
A snapshot of the cancellation generation at the start of a turn.
Created via CancellationHandle::checkpoint or TurnCancellation::new,
this value records the generation counter at creation time. If the counter
changes (because CancellationController::interrupt was called), the
checkpoint reports itself as cancelled.
The agent loop passes a TurnCancellation into model and tool calls so
they can bail out cooperatively.
§Example
use agentkit_core::{CancellationController, TurnCancellation};
let controller = CancellationController::new();
let checkpoint = TurnCancellation::new(controller.handle());
assert!(!checkpoint.is_cancelled());
controller.interrupt();
assert!(checkpoint.is_cancelled());Implementations§
Source§impl TurnCancellation
impl TurnCancellation
Sourcepub fn new(handle: CancellationHandle) -> Self
pub fn new(handle: CancellationHandle) -> Self
Creates a checkpoint from the given handle, capturing its current generation.
§Arguments
handle- TheCancellationHandleto observe.
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
Returns the generation that was captured when this checkpoint was created.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if the controller has been interrupted since this checkpoint was created.
Sourcepub async fn cancelled(&self)
pub async fn cancelled(&self)
Waits asynchronously until this checkpoint becomes cancelled.
Useful in tokio::select! to race a model call against user interruption.
Sourcepub fn handle(&self) -> &CancellationHandle
pub fn handle(&self) -> &CancellationHandle
Returns a reference to the underlying CancellationHandle.
Trait Implementations§
Source§impl Clone for TurnCancellation
impl Clone for TurnCancellation
Source§fn clone(&self) -> TurnCancellation
fn clone(&self) -> TurnCancellation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more