pub struct WaitGroup(/* private fields */);
Expand description
Re-export functions of crate atomic-waitgroup
Implementations§
Source§impl WaitGroup
impl WaitGroup
pub fn new() -> WaitGroup
Sourcepub fn add_guard(&self) -> WaitGroupGuard
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;
});
Sourcepub async fn wait_to(&self, target: usize) -> bool
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.
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