Struct atomic_waitgroup::WaitGroup
source · pub struct WaitGroup(/* private fields */);Implementations§
source§impl WaitGroup
impl WaitGroup
pub fn new() -> Self
sourcepub fn add(&self, i: usize)
pub fn add(&self, i: usize)
Add specified count.
§NOTE
Although add() does not conflict with wait()/wait_to(), Be sure to avoid concurrency of add() & done() which might lead to ill logic.
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.
sourcepub async fn wait(&self)
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.
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