pub struct Counter(/* private fields */);Expand description
A shared count with an asynchronous capacity notification.
Clones use the same count and capacity, but each clone registers its own waiting task.
Implementations§
Source§impl Counter
impl Counter
Sourcepub fn get(&self) -> CounterGuard
pub fn get(&self) -> CounterGuard
Acquires one count and returns a guard that releases it on drop.
This does not wait for capacity; call available
first when exceeding the configured capacity is not acceptable.
Sourcepub fn set_capacity(&self, cap: usize)
pub fn set_capacity(&self, cap: usize)
Changes the capacity and wakes waiting tasks.
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Returns true if another count can be acquired without exceeding the 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 !RefUnwindSafe for Counter
impl !Send for Counter
impl !Sync for Counter
impl !UnwindSafe for Counter
impl Freeze for Counter
impl Unpin for Counter
impl UnsafeUnpin 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