Struct async_waitgroup::WaitGroup
source · 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 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