util: PollSemaphore
should expose available_permits
#3682
Labels
A-tokio-util
Area: The tokio-util crate
C-enhancement
Category: A PR with an enhancement or bugfix.
C-feature-request
Category: A feature request.
E-easy
Call for participation: Experience needed to fix: Easy / not much
E-help-wanted
Call for participation: Help is requested to fix this issue.
Is your feature request related to a problem? Please describe.
The
tokio::sync::Semaphore
type provides aSemaphore::available_permits
method which returns the current number of permits available on the semaphore.tokio_util::sync::PollSemaphore
does not expose such a method. It is possible to usePollSemaphore::into_inner
orPollSemaphore::clone_inner
to unwrap the inner semaphore, but this may require cloning/dropping the semaphore'sArc
which shouldn't be necessary to access the permits.Describe the solution you'd like
We should add a
PollSemaphore::available_permits
that callsSemaphore::available_permits
on the innerSemaphore
. We could probably also add aPollSemaphore::add_permits
method while we're here. This should be pretty trivial to add.Describe alternatives you've considered
Alternatively, we could just add a
PollSemaphore::inner_ref
or similar method for borrowing the innerSemaphore
.PollSemaphore
could even implementAsRef<Semaphore>
.This might be a little more complex to use (
semaphore.as_ref().available_permits()
vssemaphore.available_permits()
) and is less visible in the API docs, but it would let us easily expose all the methods on the inner type transparently without having to wrap them. This could be both a pro or a con, if there are methods of the innerSemaphore
type thatPollSemaphore
should not expose...The text was updated successfully, but these errors were encountered: