pub struct Set<T> { /* private fields */ }coroutine only.Expand description
A set of Handles that can be joined concurrently.
When the set is dropped, all handles added to the set are aborted.
Implementations§
Source§impl<T: Send + 'static> Set<T>
impl<T: Send + 'static> Set<T>
Sourcepub fn add(&mut self, handle: Handle<T>)
pub fn add(&mut self, handle: Handle<T>)
Add one handle to the set.
A task will be spawned onto the background runtime to start joining
the handle. Therefore, when there are a lot of handles,
it’s better to collect them first into a Vec, then use extend
to add them to the set at once, to put slightly less pressure on the runtime.
The handle will also become not abortable, but dropping the Set will abort all handles.
Sourcepub fn extend<I: IntoIterator<Item = Handle<T>>>(&mut self, iter: I)
pub fn extend<I: IntoIterator<Item = Handle<T>>>(&mut self, iter: I)
Add multiple handles to the set
The handles will become not abortable, but dropping the Set will abort all handles.
Sourcepub fn extend_flatten<E, I: IntoIterator<Item = Result<Handle<T>, E>>>(
&mut self,
iter: I,
) -> Vec<E>
pub fn extend_flatten<E, I: IntoIterator<Item = Result<Handle<T>, E>>>( &mut self, iter: I, ) -> Vec<E>
Add multiple handles to the set, from a set of results, the errors are collected and returned.
The handles will become not abortable, but dropping the Set will abort all handles.
Sourcepub async fn next(&mut self) -> Option<Result<T>>
pub async fn next(&mut self) -> Option<Result<T>>
Wait for the next handle to be available, and return it’s result,
or None if the set is empty, meaning all handles are joined.
Sourcepub fn block(&mut self) -> Option<Result<T>>
pub fn block(&mut self) -> Option<Result<T>>
Wait for the next handle to be available, and return it’s result,
or None if the set is empty, meaning all handles are joined.
§Blocking
Do not use this in an async context, since it will block the runtime,
and will panic if the thread is currently driving IO.
Use next().await instead.