mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-20 00:00:08 +02:00
## Motivation The `tokio::sync::Semaphore` type provides a [`Semaphore::available_permits` method][1] which returns the current number of permits available on the semaphore. `tokio_util::sync::PollSemaphore` [does not expose such a method][2]. It is possible to use `PollSemaphore::into_inner` or `PollSemaphore::clone_inner` to unwrap the inner semaphore, but this may require cloning/dropping the semaphore's `Arc` which shouldn't be necessary to access the permits. ## Solution This commit adds `PollSemaphore::available_permits`. It also adds `PollSemaphore::add_permits` and an `AsRef<Semaphore>` impl while we're here. [1]: https://docs.rs/tokio/1.4.0/tokio/sync/struct.Semaphore.html#method.available_permits [2]: https://docs.rs/tokio-util/0.6.5/tokio_util/sync/struct.PollSemaphore.html#implementations Closes #3682