Skip to content

Commit

Permalink
Add a Semaphore::count() method
Browse files Browse the repository at this point in the history
This public method can be used to query the currently available concurrency in
the semaphore without affecting its state.
  • Loading branch information
mqudsi committed Oct 7, 2022
1 parent 84e88ce commit a65b43b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ impl Semaphore

return true;
}

/// Returns the currently available count of the semaphore.
///
/// Note that this may race with other calls such as `release()` or `wait()`.
pub fn count(&self) -> Count {
self.count.load(Ordering::Relaxed)
}
}

impl<'a> Awaitable<'a> for Semaphore {
Expand Down

0 comments on commit a65b43b

Please sign in to comment.