pub struct BackgroundToolTracker { /* private fields */ }Expand description
Tracks in-flight background tool executions for cancellation.
Uses [DashMap] internally so that spawned tasks can remove themselves
upon completion while the control lane concurrently spawns or cancels
other tasks.
Implementations§
Source§impl BackgroundToolTracker
impl BackgroundToolTracker
Sourcepub fn new() -> BackgroundToolTracker
pub fn new() -> BackgroundToolTracker
Create a new, empty tracker.
Sourcepub fn spawn(
&self,
call_id: String,
task: JoinHandle<()>,
cancel: CancellationToken,
)
pub fn spawn( &self, call_id: String, task: JoinHandle<()>, cancel: CancellationToken, )
Register a spawned background task.
The call_id is the unique identifier for the function call (usually
from FunctionCall::id). The caller provides both a
[JoinHandle] (for aborting) and a [CancellationToken] (for
cooperative cancellation).
Sourcepub fn cancel(&self, call_ids: &[String])
pub fn cancel(&self, call_ids: &[String])
Cancel specific tool calls by their IDs.
For each matching ID the cancellation token is triggered and the task handle is aborted, providing belt-and-suspenders cleanup. Non-existent IDs are silently ignored.
Sourcepub fn cancel_all(&self)
pub fn cancel_all(&self)
Cancel all in-flight background tasks.
Useful during session shutdown to ensure no orphaned tasks remain.
Sourcepub fn active_ids(&self) -> Vec<String>
pub fn active_ids(&self) -> Vec<String>
Get IDs of active background tool calls.
Sourcepub fn remove(&self, call_id: &str)
pub fn remove(&self, call_id: &str)
Remove a completed task (called when background task finishes).
This is typically invoked by the spawned task itself to clean up the tracker entry once execution is done.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of active background tasks.
Trait Implementations§
Source§impl Default for BackgroundToolTracker
impl Default for BackgroundToolTracker
Source§fn default() -> BackgroundToolTracker
fn default() -> BackgroundToolTracker
Auto Trait Implementations§
impl Freeze for BackgroundToolTracker
impl !RefUnwindSafe for BackgroundToolTracker
impl Send for BackgroundToolTracker
impl Sync for BackgroundToolTracker
impl Unpin for BackgroundToolTracker
impl UnwindSafe for BackgroundToolTracker
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
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].