Struct taskwait::TaskGroup[][src]

pub struct TaskGroup { /* fields omitted */ }

Group of tasks to be waited on.

Implementations

impl TaskGroup[src]

pub fn new() -> Self[src]

Creates new task group

pub fn add(&self, n: u32)[src]

Increases the task counter.

This is used to indicate an intention for an upcoming task. Alternatively, this can be used to decrement the task counter.

Call to this function should be matched by call to Self::done. If the call to done() needs to be done in a RAII manner use Self::add_work

pub fn add_work(&self, n: u32) -> Work[src]

Creates a work which does increment the task counter by n. The returned Work decrements the counter when dropped.

pub fn done(&self)[src]

Decrements the task counter.

pub fn done_n(&self, n: u32)[src]

Decrements the task counter by n

pub fn wait(&self) -> WaitFuture

Notable traits for WaitFuture

impl Future for WaitFuture type Output = i64;
[src]

Returns the WaitFuture When awaited the future returns the internal counter, which can be 0 or -ve. A value can be -ve if there were more TaskGroup::done calls than TaskGroup::add. The caller can use this to maintain an invariant in case of any mis-behaving tasks.

The future when resolved also resets the internal counter to zero. The taskgroup then can be reused.

use taskwait::TaskGroup;
 
#[tokio::main]
async fn main() {
    let tg = TaskGroup::new();
     
    // ... Spawn tasks ...

    let n = tg.wait().await;
    if n < 0 {
        // Return Error
    }
}

Trait Implementations

impl Clone for TaskGroup[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.