pub struct TaskRegistry { /* private fields */ }Expand description
A clone-safe registry of spawned tasks.
TaskRegistry: Clone + Send + Sync. Cloning is cheap (Arc bump) and
all clones share the same underlying task list.
Implementations§
Source§impl TaskRegistry
impl TaskRegistry
Sourcepub fn new(shutdown: ShutdownToken) -> Self
pub fn new(shutdown: ShutdownToken) -> Self
Construct an empty registry linked to the given shutdown token.
Sourcepub fn spawn<F>(
&self,
name: &'static str,
kind: TaskKind,
fut: F,
) -> AbortHandle
pub fn spawn<F>( &self, name: &'static str, kind: TaskKind, fut: F, ) -> AbortHandle
Spawn a tracked task.
The closure receives no arguments — if it needs the shutdown token
or a sub-registry, capture them via move. Use
shutdown to obtain a clone of the token.
Returns an AbortHandle so the caller can force-abort the task
if needed (e.g., a per-peer handler when the peer disconnects). The
real JoinHandle is held by the registry and is awaited in
join_all at shutdown. Callers that want to wait
for a single task to complete must await by their own means (a
tokio::sync::oneshot or similar inside fut) — the registry is
optimised for the shutdown-join case, not per-task completion.
Sourcepub fn shutdown(&self) -> &ShutdownToken
pub fn shutdown(&self) -> &ShutdownToken
Borrow the shutdown token this registry is linked to.
Sourcepub async fn join_all(&self, deadline: Duration) -> Result<()>
pub async fn join_all(&self, deadline: Duration) -> Result<()>
Await all tracked tasks up to deadline; abort laggards.
Returns Ok(()) if every task exited inside the deadline.
Returns ServiceError::ShutdownDeadlineExceeded otherwise, with
the count of aborted tasks.
Sourcepub fn snapshot(&self) -> Vec<TaskSummary>
pub fn snapshot(&self) -> Vec<TaskSummary>
Snapshot of currently-tracked tasks (live only; completed tasks
are not garbage-collected until join_all).
Trait Implementations§
Source§impl Clone for TaskRegistry
impl Clone for TaskRegistry
Source§fn clone(&self) -> TaskRegistry
fn clone(&self) -> TaskRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more