pub struct JoinSet<T> { /* private fields */ }Expand description
A set of spawned tasks, joined in the order they finish.
Dropping the set cancels every task still in it, as dropping their
Task handles would; detach_all lets them run on.
let mut set = nuclei::task::JoinSet::new();
for i in 0..4u64 {
set.spawn(async move { i * 10 });
}
let mut sum = 0;
while let Some(out) = set.join_next().await {
sum += out.unwrap();
}
assert_eq!(sum, 60);Implementations§
Source§impl<T> JoinSet<T>
impl<T> JoinSet<T>
Sourcepub fn insert(&mut self, task: Task<T>) -> AbortHandle
pub fn insert(&mut self, task: Task<T>) -> AbortHandle
Takes task into the set and answers a handle that cancels it.
Sourcepub fn spawn<F>(&mut self, future: F) -> AbortHandle
pub fn spawn<F>(&mut self, future: F) -> AbortHandle
Spawns future as spawn does, into the set.
Sourcepub fn spawn_local<F>(&mut self, future: F) -> AbortHandlewhere
F: Future<Output = T> + 'static,
T: 'static,
pub fn spawn_local<F>(&mut self, future: F) -> AbortHandlewhere
F: Future<Output = T> + 'static,
T: 'static,
Spawns future as spawn_local does,
into the set.
Sourcepub fn spawn_blocking<F>(&mut self, f: F) -> AbortHandle
pub fn spawn_blocking<F>(&mut self, f: F) -> AbortHandle
Runs f on the blocking pool, into the set.
Sourcepub fn spawn_on<F>(&mut self, future: F, handle: &RuntimeHandle) -> AbortHandle
pub fn spawn_on<F>(&mut self, future: F, handle: &RuntimeHandle) -> AbortHandle
Spawns future on the runtime handle refers to, into the set.
Sourcepub async fn join_next(&mut self) -> Option<Result<T, JoinError>>
pub async fn join_next(&mut self) -> Option<Result<T, JoinError>>
The output of the next task to finish, None when the set is empty.
A task that was cancelled or panicked gives its JoinError.
Sourcepub async fn join_next_with_id(&mut self) -> Option<Result<(Id, T), JoinError>>
pub async fn join_next_with_id(&mut self) -> Option<Result<(Id, T), JoinError>>
join_next, with the id of the task.
Sourcepub fn try_join_next(&mut self) -> Option<Result<T, JoinError>>
pub fn try_join_next(&mut self) -> Option<Result<T, JoinError>>
The output of a task that has finished, without waiting: None when
none has (the set may still hold tasks).
Sourcepub fn poll_join_next(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Option<Result<(Id, T), JoinError>>>
pub fn poll_join_next( &mut self, cx: &mut Context<'_>, ) -> Poll<Option<Result<(Id, T), JoinError>>>
Polls for the next finished task.
Sourcepub async fn join_all(self) -> Vec<T>
pub async fn join_all(self) -> Vec<T>
Every task’s output, in finishing order.
§Panics
When a task panicked (its panic is resumed) or was cancelled.
Sourcepub fn abort_all(&mut self)
pub fn abort_all(&mut self)
Cancels every task in the set; they stay in it, and join_next gives
each one’s cancellation (or its output, if it finished first).
Sourcepub fn detach_all(&mut self)
pub fn detach_all(&mut self)
Takes every task out of the set and lets each run to its end. The slots go with them, so a detached task’s later wake meets none.
Trait Implementations§
Source§impl<T, F> Extend<F> for JoinSet<T>
impl<T, F> Extend<F> for JoinSet<T>
Source§fn extend<I: IntoIterator<Item = F>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = F>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)