pub struct WaitGroup { /* private fields */ }
Expand description
Enables tasks to synchronize the beginning or end of some computation.
§Examples
use async_waitgroup::WaitGroup;
// Create a new wait group.
let wg = WaitGroup::new();
for _ in 0..4 {
// Create another reference to the wait group.
let wg = wg.clone();
tokio::spawn(async move {
// Do some work.
// Drop the reference to the wait group.
drop(wg);
});
}
// Block until all tasks have finished their work.
wg.wait().await;
Implementations§
Source§impl WaitGroup
impl WaitGroup
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new wait group and returns the single reference to it.
§Examples
use async_waitgroup::WaitGroup;
let wg = WaitGroup::new();
Sourcepub fn wait(self) -> Wait ⓘ
pub fn wait(self) -> Wait ⓘ
Drops this reference and waits until all other references are dropped.
§Examples
use async_waitgroup::WaitGroup;
let wg = WaitGroup::new();
tokio::spawn({
let wg = wg.clone();
async move {
// Block until both tasks have reached `wait()`.
wg.wait().await;
}
});
// Block until all tasks have finished their work.
wg.wait().await;
Sourcepub fn wait_blocking(self)
pub fn wait_blocking(self)
Waits using the blocking strategy.
§Examples
use std::thread;
use async_waitgroup::WaitGroup;
let wg = WaitGroup::new();
thread::spawn({
let wg = wg.clone();
move || {
wg.wait_blocking();
}
});
wg.wait_blocking();
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WaitGroup
impl RefUnwindSafe for WaitGroup
impl Send for WaitGroup
impl Sync for WaitGroup
impl Unpin for WaitGroup
impl UnwindSafe for WaitGroup
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more