pub struct CountedTaskSet { /* private fields */ }Expand description
Short-lived tasks of one owner, counted instead of registered one by one.
The other spawn methods of TaskGroup give every task an id, metadata and an abort handle
in the group’s registry, so the group can report, wait for and abort each one. That costs
several locks and allocations per task, which dominates tasks that live for one request.
A set keeps only a count of its running tasks.
Its tasks run on the group’s runtime and are tracked by the group, so the group’s shutdown
waits for them like for its draining operation tasks. Every task races the cancellation
token the set was created with: cancelling it drops each running task’s future at its next
poll, which is when an aborted task stops too. The owner closes the set and waits for it with
drain_until. Tasks of a set its owner dropped keep running, owned by
the group: a group shutdown that reaches its deadline cancels the token of every set it
created, where it aborts its registered tasks.
Implementations§
Source§impl CountedTaskSet
impl CountedTaskSet
Sourcepub fn spawn<F>(&self, future: F) -> RuntimeResult<()>
pub fn spawn<F>(&self, future: F) -> RuntimeResult<()>
Spawns future as a counted task.
A panic in the future ends only its task and is counted in Self::panicked.
§Errors
Returns a closed error once the set is closed or its token cancelled, and the group’s admission error once the group no longer accepts tasks.
Sourcepub async fn drain_until(&self, deadline: ShutdownDeadline) -> bool
pub async fn drain_until(&self, deadline: ShutdownDeadline) -> bool
Closes the set and waits until every task has finished or deadline passes.
Tasks still running at the deadline are stopped through the set’s token, and the call
waits up to one second for their futures to be dropped, as
OperationContext::wait does for aborted tasks. Returns
whether every task finished before the deadline.