pub struct TaskSpawner { /* private fields */ }Expand description
Narrow capability for spawning work owned by an existing TaskGroup.
Cloning this value shares lifecycle authority; it cannot create a runtime root, expose a raw Tokio handle, detach work, or outlive owner shutdown.
Implementations§
Source§impl TaskSpawner
impl TaskSpawner
Sourcepub fn group_id(&self) -> TaskGroupId
pub fn group_id(&self) -> TaskGroupId
Returns the identity of the owned task group.
Sourcepub fn group_name(&self) -> &str
pub fn group_name(&self) -> &str
Returns the diagnostic name of the owned task group.
Sourcepub fn cancellation_token(&self) -> CancellationToken
pub fn cancellation_token(&self) -> CancellationToken
Returns a child token cancelled by owner shutdown.
Cancelling the returned token does not cancel the owning task group.
Sourcepub fn spawn<F>(
&self,
name: impl Into<TaskName>,
kind: TaskKind,
future: F,
) -> RuntimeResult<TaskId>
pub fn spawn<F>( &self, name: impl Into<TaskName>, kind: TaskKind, future: F, ) -> RuntimeResult<TaskId>
Registers future as parent-owned work.
The future must be Send and tasks have no ordering guarantee relative
to other submissions. Owner shutdown cancels and awaits the registered
task according to the parent task group’s deadline.
§Errors
Returns an error when the parent group is shutting down or closed.
Sourcepub fn spawn_service<F>(
&self,
name: impl Into<TaskName>,
future: F,
) -> RuntimeResult<TaskId>
pub fn spawn_service<F>( &self, name: impl Into<TaskName>, future: F, ) -> RuntimeResult<TaskId>
Registers a long-lived service future with a custom shutdown protocol.
The future must observe a cancellation token and perform its own
ordered cleanup. Use Self::spawn_cancellable_service when owner
cancellation may drop the future immediately.
§Errors
Returns an error when the parent group is shutting down or closed.
Sourcepub fn spawn_cancellable_service<F>(
&self,
name: impl Into<TaskName>,
future: F,
) -> RuntimeResult<TaskId>
pub fn spawn_cancellable_service<F>( &self, name: impl Into<TaskName>, future: F, ) -> RuntimeResult<TaskId>
Registers a service that exits when either its future completes or its owner is cancelled.
§Errors
Returns an error when the parent group is shutting down or closed.
Sourcepub fn spawn_critical<F>(
&self,
name: impl Into<TaskName>,
kind: TaskKind,
failures: CriticalFailureState,
future: F,
) -> RuntimeResult<TaskId>
pub fn spawn_critical<F>( &self, name: impl Into<TaskName>, kind: TaskKind, failures: CriticalFailureState, future: F, ) -> RuntimeResult<TaskId>
Registers parent-owned work whose panic is recorded as a critical failure.
The failure record stays pending until a handler takes it, so a full notification channel cannot lose the fact that the task failed.
§Errors
Returns an error when the parent group is shutting down or closed.
Sourcepub fn spawn_critical_service<F>(
&self,
name: impl Into<TaskName>,
failures: CriticalFailureState,
future: F,
) -> RuntimeResult<TaskId>
pub fn spawn_critical_service<F>( &self, name: impl Into<TaskName>, failures: CriticalFailureState, future: F, ) -> RuntimeResult<TaskId>
Registers a critical service that must run until its owner is cancelled.
A panic and a return before owner cancellation are both recorded; owner cancellation is an expected exit and records nothing.
§Errors
Returns an error when the parent group is shutting down or closed.