Struct taskwait::TaskGroup [−][src]
Group of tasks to be waited on.
Implementations
impl TaskGroup
[src]
pub fn new() -> Self
[src]
Creates new task group
pub fn add(&self)
[src]
Increases the task counter by 1.
This is used to indicate an intention for an upcoming task.
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_n(&self, n: u32)
[src]
Increases the task counter by n
.
This is used to indicate an intention for an upcoming task.
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 by 1.
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]
Notable traits for WaitFuture
impl Future for WaitFuture type Output = i64;
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
Auto Trait Implementations
impl !RefUnwindSafe for TaskGroup
impl Send for TaskGroup
impl Sync for TaskGroup
impl Unpin for TaskGroup
impl !UnwindSafe for TaskGroup
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,