pub struct Counter(/* private fields */);Expand description
Simple counter with ability to notify task on reaching specific number
Counter could be cloned, total count is shared across all clones.
Implementations§
Source§impl Counter
impl Counter
Sourcepub fn get(&self) -> CounterGuard
pub fn get(&self) -> CounterGuard
Get counter guard.
Sourcepub fn set_capacity(&self, cap: usize)
pub fn set_capacity(&self, cap: usize)
Set counter capacity
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Check is counter has free capacity.
Sourcepub async fn available(&self)
pub async fn available(&self)
Waits until the counter has free capacity.
Returns immediately if there is capacity available. Otherwise, registers the current task for wakeup and waits until a slot is freed.
Waits until the counter reaches its capacity (i.e., becomes unavailable).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Counter
impl !RefUnwindSafe for Counter
impl !Send for Counter
impl !Sync for Counter
impl Unpin for Counter
impl UnsafeUnpin for Counter
impl !UnwindSafe for Counter
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