Skip to main content

Set

Struct Set 

Source
pub struct Set<T> { /* private fields */ }
Available on crate feature 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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T> Drop for Set<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
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 Set<T>
where JoinSet<Result<T, Error>>: Freeze,

§

impl<T> RefUnwindSafe for Set<T>
where JoinSet<Result<T, Error>>: RefUnwindSafe,

§

impl<T> Send for Set<T>
where JoinSet<Result<T, Error>>: Send,

§

impl<T> Sync for Set<T>
where JoinSet<Result<T, Error>>: Sync,

§

impl<T> Unpin for Set<T>
where JoinSet<Result<T, Error>>: Unpin,

§

impl<T> UnsafeUnpin for Set<T>
where JoinSet<Result<T, Error>>: UnsafeUnpin,

§

impl<T> UnwindSafe for Set<T>
where JoinSet<Result<T, Error>>: UnwindSafe,

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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.