DiscardingSpawnGroup

Struct DiscardingSpawnGroup 

Source
pub struct DiscardingSpawnGroup {
    pub is_cancelled: bool,
    /* private fields */
}
Expand description

Discarding Spawn Group

A kind of a spawn group that spawns asynchronous tasks that returns nothing, implicitly waits for all spawned tasks to finish before being dropped and releases all the resources 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.

Fields§

§is_cancelled: bool

A field that indicates if the spawn group has been cancelled

Implementations§

Source§

impl DiscardingSpawnGroup

Source

pub fn dont_wait_at_drop(&mut self)

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

Source§

impl DiscardingSpawnGroup

Source

pub fn new(num_of_threads: usize) -> Self

Instantiates DiscardingSpawnGroup 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 DiscardingSpawnGroup

Source

pub fn spawn_task( &mut self, priority: Priority, closure: impl Future<Output = ()> + Send + 'static, )

Spawns a new task into the spawn group

§Parameters
  • priority: priority to use
  • closure: an async closure that doesn’t return anything
Source

pub fn spawn_task_unlessed_cancelled( &mut self, priority: Priority, closure: impl Future<Output = ()> + 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 doesn’t return anything
Source

pub fn cancel_all(&mut self)

Cancels all running task in the spawn group

Source§

impl DiscardingSpawnGroup

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_spawn_group() 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 DiscardingSpawnGroup

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.

Trait Implementations§

Source§

impl Default for DiscardingSpawnGroup

Source§

fn default() -> Self

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

Source§

impl Drop for DiscardingSpawnGroup

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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<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.