Skip to main content

TaskSet

Struct TaskSet 

Source
pub struct TaskSet<T> { /* private fields */ }
Expand description

A set of spawned tasks, joined as they complete — the seam replacement for tokio::task::JoinSet.

JoinSet is a fourth spelling of tokio::spawn, and the one no seam guard caught: JoinSet::spawn calls tokio::spawn internally, so it panics with “there is no reactor running” on any thread that is not inside a tokio runtime — which on RTEMS is every callback-band worker. Measured on target: the CA client’s transport manager died on cbMedium at its first connect (doc/calink-rtems-design.md §11.1). Naming it here means a call site can express “spawn a set of tasks and reap them as they finish” without reaching past the seam.

The three properties call sites depend on, all preserved:

  • Concurrency — every member runs independently; joining one does not block the others.
  • Pair-by-valueSelf::join_next yields whichever member finished first, so a task that returns its own key can be matched to its state.
  • Abort on drop — dropping the set cancels every member that has not finished, which is the property that distinguishes a JoinSet from a bag of detached JoinHandles.

Implementations§

Source§

impl<T> TaskSet<T>

Source

pub fn new() -> Self

An empty set.

Source

pub fn len(&self) -> usize

Number of members that have not yet been joined.

Source

pub fn is_empty(&self) -> bool

true when no member is outstanding.

Source§

impl<T: Send + 'static> TaskSet<T>

Source

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

Spawn future into the set — through spawn, so the RTEMS build lands it on a callback band instead of demanding a tokio runtime.

Source

pub async fn join_next(&mut self) -> Option<Result<T, TaskJoinError>>

Wait for the next member to finish and return its result, removing it from the set. None when the set is empty — matching JoinSet::join_next, so a select! arm on it goes quiet rather than spinning once every task has been reaped.

Cancel-safe: the returned future holds no state of its own, so a select! that drops it loses nothing.

Trait Implementations§

Source§

impl<T> Default for TaskSet<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Drop for TaskSet<T>

Source§

fn drop(&mut self)

Cancel every outstanding member — JoinSet’s drop behaviour, and the reason a call site reaches for a set rather than a Vec of handles.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> Freeze for TaskSet<T>

§

impl<T> RefUnwindSafe for TaskSet<T>

§

impl<T> Send for TaskSet<T>
where T: Send,

§

impl<T> Sync for TaskSet<T>
where T: Send,

§

impl<T> Unpin for TaskSet<T>

§

impl<T> UnsafeUnpin for TaskSet<T>

§

impl<T> UnwindSafe for TaskSet<T>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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