Skip to main content

CountedTaskSet

Struct CountedTaskSet 

Source
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

Source

pub fn spawn<F>(&self, future: F) -> RuntimeResult<()>
where F: Future<Output = ()> + Send + 'static,

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.

Source

pub fn close(&self)

Stops accepting tasks. Running tasks continue.

Source

pub fn active(&self) -> usize

Returns the number of tasks that have not finished.

Source

pub fn panicked(&self) -> u64

Returns the number of tasks whose future panicked.

Source

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.

Auto Trait Implementations§

§

impl !RefUnwindSafe for CountedTaskSet

§

impl !UnwindSafe for CountedTaskSet

§

impl Forget for CountedTaskSet

§

impl Freeze for CountedTaskSet
where *const ArcInner<CountedTaskSetInner> is !null: Freeze, PhantomData<ArcInner<CountedTaskSetInner>>: Freeze,

§

impl Move for CountedTaskSet

§

impl Send for CountedTaskSet
where Arc<CountedTaskSetInner>: Send,

§

impl Sync for CountedTaskSet
where Arc<CountedTaskSetInner>: Sync,

§

impl Unpin for CountedTaskSet
where Arc<CountedTaskSetInner>: Unpin,

§

impl UnsafeUnpin for CountedTaskSet
where *const ArcInner<CountedTaskSetInner> is !null: UnsafeUnpin, PhantomData<ArcInner<CountedTaskSetInner>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more