Allow Semaphore to decrease the number of permits #5308
Labels
A-tokio
Area: The main tokio crate
C-feature-request
Category: A feature request.
M-sync
Module: tokio/sync
Is your feature request related to a problem? Please describe.
Semaphore
has a method to add permits, but misses a symmetric method to decrease the number of permits.Sometimes a limit on the amount of the available resource can be set too large and although all the existing permits are not used their number cannot be reduced.
Describe the solution you'd like
Add methods
fn remove_permits(count: usize) -> usize
that would remove up tocount
permits. If not enough permits are available, it would remove only the available ones and return the number of permits removed.Describe alternatives you've considered
Don't know if there is any workaround for that.
Additional context
I'm using a semaphore to limit the amount of memory used by my program. The user is able to dynamically change the limit, but the current implementation of the semaphore allows them to only increase the limit, and if they accidentally set it too high, they have no chance to correct the error without resetting the whole thing (restarting the whole app).
The text was updated successfully, but these errors were encountered: