ScopedJoinSet

Struct ScopedJoinSet 

Source
pub struct ScopedJoinSet<'scope, T>
where T: 'static,
{ /* private fields */ }
Expand description

A scoped wrapper around tokio::task::JoinSet for dynamically spawning and awaiting multiple asynchronous tasks.

ScopedJoinSet allows you to spawn futures that are bound to a specific lifetime 'scope, ensuring all tasks outlive the scope in which they are spawned. Unlike a standard JoinSet, this structure internally tracks uniquely-owned pinned futures via FutureHolder, while exposing a weak reference (WeakFuture) for safe polling.

§Features

  • Scoped Futures: Ensures futures cannot outlive the provided 'scope.
  • Dynamic Spawning: Tasks can be spawned dynamically at runtime.
  • Cancellation Safe: join_next() is cancellation safe; tasks remain in the set until they complete and are awaited.
  • Automatic Abort: Dropping a FutureHolder aborts its associated task.

§Safety

  • Each spawned task has exactly one FutureHolder (owning the Pin<Box> of the future) and one WeakFuture (polling handle).
  • FutureHolder tracks whether the future is alive using an AtomicBool.

Implementations§

Source§

impl<'scope, T> ScopedJoinSet<'scope, T>
where T: 'static,

Source

pub fn new() -> Self

Source

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

Source

pub fn is_empty(&self) -> bool

Source

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

Trait Implementations§

Source§

impl<'scope, T> Default for ScopedJoinSet<'scope, T>
where T: 'static + Default,

Source§

fn default() -> ScopedJoinSet<'scope, T>

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

impl<'scope, T> Send for ScopedJoinSet<'scope, T>

Auto Trait Implementations§

§

impl<'scope, T> Freeze for ScopedJoinSet<'scope, T>

§

impl<'scope, T> !RefUnwindSafe for ScopedJoinSet<'scope, T>

§

impl<'scope, T> !Sync for ScopedJoinSet<'scope, T>

§

impl<'scope, T> Unpin for ScopedJoinSet<'scope, T>

§

impl<'scope, T> !UnwindSafe for ScopedJoinSet<'scope, 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, 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.