ErrSpawnGroup

Struct ErrSpawnGroup 

Source
pub struct ErrSpawnGroup<ValueType, ErrorType> {
    pub is_cancelled: bool,
    /* private fields */
}
Expand description

Err Spawn Group

A kind of a spawn group that spawns asynchronous child tasks that returns a value of Result<ValueType, ErrorType>, that implicitly wait for the spawned tasks to return before being dropped unless by explicitly calling dont_wait_at_drop()

Child tasks are spawned by calling either spawn_task() or spawn_task_unless_cancelled() methods.

Running child tasks can be cancelled by calling cancel_all() method.

Child tasks spawned to a spawn group execute concurrently, and may be scheduled in any order.

It dereferences into a futures crate Stream type where the results of each finished child task is stored and it pops out the result in First-In First-Out FIFO order whenever it is being used

Fields§

§is_cancelled: bool

A field that indicates if the spawn group had been cancelled

Implementations§

Source§

impl<ValueType, ErrorType> ErrSpawnGroup<ValueType, ErrorType>

Source

pub fn new(num_of_threads: usize) -> Self

Instantiates ErrSpawnGroup with a specific number of threads to use in the underlying threadpool when polling futures

§Parameters
  • num_of_threads: number of threads to use
Source§

impl<ValueType, ErrorType> ErrSpawnGroup<ValueType, ErrorType>

Source

pub fn dont_wait_at_drop(&mut self)

Don’t implicity wait for spawned child tasks to finish before being dropped

Source§

impl<ValueType, ErrorType> ErrSpawnGroup<ValueType, ErrorType>

Source

pub fn spawn_task<F>(&mut self, priority: Priority, closure: F)
where F: Future<Output = Result<ValueType, ErrorType>> + Send + 'static,

Spawns a new task into the spawn group

§Parameters
  • priority: priority to use
  • closure: an async closure that return a value of type Result<ValueType, ErrorType>
Source

pub fn cancel_all(&mut self)

Cancels all running task in the spawn group

Source

pub fn spawn_task_unlessed_cancelled<F>( &mut self, priority: Priority, closure: F, )
where F: Future<Output = Result<ValueType, ErrorType>> + Send + 'static,

Spawn a new task only if the group is not cancelled yet, otherwise does nothing

§Parameters
  • priority: priority to use
  • closure: an async closure that return a value of type Result<ValueType, ErrorType>
Source§

impl<ValueType, ErrorType> ErrSpawnGroup<ValueType, ErrorType>

Source

pub async fn first(&self) -> Option<Result<ValueType, ErrorType>>

Returns the first element of the stream, or None if it is empty.

Source§

impl<ValueType, ErrorType> ErrSpawnGroup<ValueType, ErrorType>

Source

pub fn stream(&self) -> impl Stream<Item = Result<ValueType, ErrorType>>

Returns an instance of the Stream trait.

Source§

impl<ValueType, ErrorType> ErrSpawnGroup<ValueType, ErrorType>

Source

pub async fn wait_for_all(&mut self)

Waits for all remaining child tasks for finish.

Source

pub fn wait_non_async(&mut self)

Waits for all remaining child tasks for finish in non async context.

Source§

impl<ValueType, ErrorType> ErrSpawnGroup<ValueType, ErrorType>

Source

pub fn is_empty(&self) -> bool

A Boolean value that indicates whether the group has any remaining tasks.

At the start of the body of a with_err_spawn_group function call, or before calling spawn_task or spawn_task_unless_cancelled methods the spawn group is always empty.

§Returns
  • true: if there’s no child task still running
  • false: if any child task is still running
Source§

impl<ValueType, ErrorType> ErrSpawnGroup<ValueType, ErrorType>

Source

pub async fn get_chunks( &self, of_count: usize, ) -> Vec<Result<ValueType, ErrorType>>

👎Deprecated since 2.0.0: Buggy

Waits for a specific number of spawned child tasks to finish and returns their respectively result as a vector

§Panics

If the of_count parameter is larger than the number of already spawned child tasks, this method panics

Remember whenever you call either wait_for_all or cancel_all methods, the child tasks’ count reverts back to zero

§Parameter
  • of_count: The number of running child tasks to wait for their results to return
§Returns

Returns a vector of length of_count elements from the spawn group instance

Trait Implementations§

Source§

impl<ValueType, ErrorType> Default for ErrSpawnGroup<ValueType, ErrorType>

Source§

fn default() -> Self

Instantiates ErrSpawnGroup with the number of threads as the number of cores as the system to use in the underlying threadpool when polling futures

Source§

impl<ValueType, ErrorType> Drop for ErrSpawnGroup<ValueType, ErrorType>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<ValueType, ErrorType> Stream for ErrSpawnGroup<ValueType, ErrorType>

Source§

type Item = Result<ValueType, ErrorType>

Values yielded by the stream.
Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
Source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more

Auto Trait Implementations§

§

impl<ValueType, ErrorType> Freeze for ErrSpawnGroup<ValueType, ErrorType>

§

impl<ValueType, ErrorType> !RefUnwindSafe for ErrSpawnGroup<ValueType, ErrorType>

§

impl<ValueType, ErrorType> Send for ErrSpawnGroup<ValueType, ErrorType>
where ValueType: Send, ErrorType: Send,

§

impl<ValueType, ErrorType> Sync for ErrSpawnGroup<ValueType, ErrorType>
where ValueType: Send, ErrorType: Send,

§

impl<ValueType, ErrorType> Unpin for ErrSpawnGroup<ValueType, ErrorType>

§

impl<ValueType, ErrorType> !UnwindSafe for ErrSpawnGroup<ValueType, ErrorType>

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> GetType for T
where T: ?Sized,

Source§

const TYPE: PhantomData<Self> = PhantomData

Acts as a metatype value
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<S> StreamExt for S
where S: Stream + ?Sized,

Source§

fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>
where Self: Unpin,

A convenience for calling Stream::poll_next() on !Unpin types.
Source§

fn next(&mut self) -> NextFuture<'_, Self>
where Self: Unpin,

Retrieves the next item in the stream. Read more
Source§

fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self>
where Self: Stream<Item = Result<T, E>> + Unpin,

Retrieves the next item in the stream. Read more
Source§

fn count(self) -> CountFuture<Self>
where Self: Sized,

Counts the number of items in the stream. Read more
Source§

fn map<T, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> T,

Maps items of the stream to new values using a closure. Read more
Source§

fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
where Self: Sized, U: Stream, F: FnMut(Self::Item) -> U,

Maps items to streams and then concatenates them. Read more
Source§

fn flatten(self) -> Flatten<Self>
where Self: Sized, Self::Item: Stream,

Concatenates inner streams. Read more
Source§

fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut>
where Self: Sized, F: FnMut(Self::Item) -> Fut, Fut: Future,

Maps items of the stream to new values using an async closure. Read more
Source§

fn filter<P>(self, predicate: P) -> Filter<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Keeps items of the stream for which predicate returns true. Read more
Source§

fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> Option<T>,

Filters and maps items of the stream using a closure. Read more
Source§

fn take(self, n: usize) -> Take<Self>
where Self: Sized,

Takes only the first n items of the stream. Read more
Source§

fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Takes items while predicate returns true. Read more
Source§

fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>
where Self: Sized, P: FnMut(Self::Item) -> Option<B>,

Maps items while predicate returns Some. Read more
Source§

fn skip(self, n: usize) -> Skip<Self>
where Self: Sized,

Skips the first n items of the stream. Read more
Source§

fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Skips items while predicate returns true. Read more
Source§

fn step_by(self, step: usize) -> StepBy<Self>
where Self: Sized,

Yields every stepth item. Read more
Source§

fn chain<U>(self, other: U) -> Chain<Self, U>
where Self: Sized, U: Stream<Item = Self::Item>,

Appends another stream to the end of this one. Read more
Source§

fn cloned<'a, T>(self) -> Cloned<Self>
where Self: Sized + Stream<Item = &'a T>, T: Clone + 'a,

Clones all items. Read more
Source§

fn copied<'a, T>(self) -> Copied<Self>
where Self: Sized + Stream<Item = &'a T>, T: Copy + 'a,

Copies all items. Read more
Source§

fn collect<C>(self) -> CollectFuture<Self, C>
where Self: Sized, C: Default + Extend<Self::Item>,

Collects all items in the stream into a collection. Read more
Source§

fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C>
where Self: Sized + Stream<Item = Result<T, E>>, C: Default + Extend<T>,

Collects all items in the fallible stream into a collection. Read more
Source§

fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B>
where Self: Sized, B: Default + Extend<Self::Item>, P: FnMut(&Self::Item) -> bool,

Partitions items into those for which predicate is true and those for which it is false, and then collects them into two collections. Read more
Source§

fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T>
where Self: Sized, F: FnMut(T, Self::Item) -> T,

Accumulates a computation over the stream. Read more
Source§

fn try_fold<T, E, F, B>( &mut self, init: B, f: F, ) -> TryFoldFuture<'_, Self, F, B>
where Self: Sized + Stream<Item = Result<T, E>> + Unpin, F: FnMut(B, T) -> Result<B, E>,

Accumulates a fallible computation over the stream. Read more
Source§

fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
where Self: Sized, F: FnMut(&mut St, Self::Item) -> Option<B>,

Maps items of the stream to new values using a state value and a closure. Read more
Source§

fn fuse(self) -> Fuse<Self>
where Self: Sized,

Fuses the stream so that it stops yielding items after the first None. Read more
Source§

fn cycle(self) -> Cycle<Self>
where Self: Sized + Clone,

Repeats the stream from beginning to end, forever. Read more
Source§

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Enumerates items, mapping them to (index, item). Read more
Source§

fn inspect<F>(self, f: F) -> Inspect<Self, F>
where Self: Sized, F: FnMut(&Self::Item),

Calls a closure on each item and passes it on. Read more
Source§

fn nth(&mut self, n: usize) -> NthFuture<'_, Self>
where Self: Unpin,

Gets the nth item of the stream. Read more
Source§

fn last(self) -> LastFuture<Self>
where Self: Sized,

Returns the last item in the stream. Read more
Source§

fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P>
where Self: Unpin, P: FnMut(&Self::Item) -> bool,

Finds the first item of the stream for which predicate returns true. Read more
Source§

fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F>
where Self: Unpin, F: FnMut(Self::Item) -> Option<B>,

Applies a closure to items in the stream and returns the first Some result. Read more
Source§

fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P>
where Self: Unpin, P: FnMut(Self::Item) -> bool,

Finds the index of the first item of the stream for which predicate returns true. Read more
Source§

fn all<P>(&mut self, predicate: P) -> AllFuture<'_, Self, P>
where Self: Unpin, P: FnMut(Self::Item) -> bool,

Tests if predicate returns true for all items in the stream. Read more
Source§

fn any<P>(&mut self, predicate: P) -> AnyFuture<'_, Self, P>
where Self: Unpin, P: FnMut(Self::Item) -> bool,

Tests if predicate returns true for any item in the stream. Read more
Source§

fn for_each<F>(self, f: F) -> ForEachFuture<Self, F>
where Self: Sized, F: FnMut(Self::Item),

Calls a closure on each item of the stream. Read more
Source§

fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F>
where Self: Unpin, F: FnMut(Self::Item) -> Result<(), E>,

Calls a fallible closure on each item of the stream, stopping on first error. Read more
Source§

fn zip<U>(self, other: U) -> Zip<Self, U>
where Self: Sized, U: Stream,

Zips up two streams into a single stream of pairs. Read more
Source§

fn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB>
where FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Sized + Stream<Item = (A, B)>,

Collects a stream of pairs into a pair of collections. Read more
Source§

fn or<S>(self, other: S) -> Or<Self, S>
where Self: Sized, S: Stream<Item = Self::Item>,

Merges with other stream, preferring items from self whenever both streams are ready. Read more
Source§

fn race<S>(self, other: S) -> Race<Self, S>
where Self: Sized, S: Stream<Item = Self::Item>,

Merges with other stream, with no preference for either stream when both are ready. Read more
Source§

fn drain(&mut self) -> Drain<'_, Self>

Yields all immediately available values from a stream. Read more
Source§

fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
where Self: Sized + Send + 'a,

Boxes the stream and changes its type to dyn Stream + Send + 'a. Read more
Source§

fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>
where Self: Sized + 'a,

Boxes the stream and changes its type to dyn Stream + 'a. Read more
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.
Source§

impl<S, T, E> TryStream for S
where S: Stream<Item = Result<T, E>> + ?Sized,

Source§

type Ok = T

The type of successful values yielded by this future
Source§

type Error = E

The type of failures yielded by this future
Source§

fn try_poll_next( self: Pin<&mut S>, cx: &mut Context<'_>, ) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

Poll this TryStream as if it were a Stream. Read more