pub struct ScopedJoinSet<'scope, T>where
T: 'scope + Send,{ /* private fields */ }Expand description
A scoped wrapper around tokio::task::JoinSet for dynamically spawning
futures with a lifetime 'scope.
Unlike normal Tokio tasks requiring 'static futures, this set accepts
futures tied to a temporary stack lifetime, as long as the
ScopedJoinSet lives long enough.
Each call to spawn places a non-'static future into the
runtime via a controlled internal mechanism (FutureHolder + WeakFuture).
§Type Parameters
'scope: The lifetime during which spawned futures must live.T: The output of each spawned future.
Implementations§
Source§impl<'scope, T> ScopedJoinSet<'scope, T>where
T: 'scope + Send,
impl<'scope, T> ScopedJoinSet<'scope, T>where
T: 'scope + Send,
Sourcepub fn spawn<F>(&mut self, task: F)
pub fn spawn<F>(&mut self, task: F)
Spawns a new scoped future into the set.
This function is analogous to tokio::spawn, but accepts futures with
the given scope lifetime.
§Parameters
task: The user future to spawn.
§Requirements
- The returned value
Tmust beSend. - The future must be
Sendand live at least'scope.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether no tasks remain.
Equivalent to JoinSet::is_empty.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of tasks currently stored in the set.
Equivalent to JoinSet::len.
Sourcepub async fn join_next(&mut self) -> Option<Result<T, JoinError>>
pub async fn join_next(&mut self) -> Option<Result<T, JoinError>>
Waits for the next completed task in the set.
Returns:
Some(Ok(T))on success.Some(Err(JoinError))on cancellation or panic.Nonewhen the set is empty.
This method is cancellation-safe: dropping the future returned by
.await does not remove the task from the set.
Sourcepub fn try_join_next(&mut self) -> Option<Result<T, JoinError>>
pub fn try_join_next(&mut self) -> Option<Result<T, JoinError>>
Attempts to join one completed task without awaiting.
This method is non-blocking and returns immediately.
Returns:
Some(Ok(T))if a task has already completed successfully,Some(Err(JoinError))if a completed task was cancelled or panicked,Noneif no tasks have completed yet or the set is empty.
This differs from join_next:
join_next()awaits the next completed task.try_join_next()returns immediately without awaiting.
§Cancellation Safety
This method is always cancellation-safe, because it does not perform any async operations and does not remove tasks unless they have already finished.
Sourcepub async fn join_all(self) -> Vec<Result<T, JoinError>>
pub async fn join_all(self) -> Vec<Result<T, JoinError>>
Waits for all tasks in the set to complete, consuming the set and returning a list of results.
The returned results are in completion order, not spawn order.
§Cancellation Safety
If this future is dropped, remaining tasks stay inside the set.
Sourcepub fn abort_all(&mut self)
pub fn abort_all(&mut self)
Aborts all currently-running tasks.
This does not await task completion; it merely issues abort signals.
To also wait for them, call join_remaining
or drop the entire set.
After calling abort_all, the set will still contain all tasks until
they complete their aborts and are polled again.