Struct WaitGroup

Source
pub struct WaitGroup(/* private fields */);
Expand description

Re-export functions of crate atomic-waitgroup

Implementations§

Source§

impl WaitGroup

Source

pub fn new() -> WaitGroup

Source

pub fn left(&self) -> usize

Return the count left inside this WaitGroup

Source

pub fn add(&self, i: usize)

Add specified count.

Source

pub fn add_guard(&self) -> WaitGroupGuard

Add one to the WaitGroup, return a guard to decrease the count on drop.

§Example
extern crate atomic_waitgroup;
use atomic_waitgroup::WaitGroup;
use tokio::runtime::Runtime;

let wg = WaitGroup::new();
let rt = Runtime::new().unwrap();
rt.block_on(async move {
    let _guard = wg.add_guard();
    tokio::spawn(async move {
        // Do something
        drop(_guard);
    });
    wg.wait().await;
});
Source

pub async fn wait_to(&self, target: usize) -> bool

Wait until specified count is left in the WaitGroup.

Return false means there’s no waiting happened.

Return true means the blocking actually happened.

§NOTE
  • Only assume one waiting future at the same time, otherwise will panic.

  • Canceling future is supported.

Source

pub async fn wait(&self)

Wait until zero count in the WaitGroup.

§NOTE
  • Only assume one waiting future at the same time, otherwise will panic.

  • Canceling future is supported.

Source

pub fn done(&self)

Decrease count by one.

Source

pub fn done_many(&self, count: usize)

Decrease count by specified value

Trait Implementations§

Source§

impl Clone for WaitGroup

Source§

fn clone(&self) -> WaitGroup

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.