udoprog / leaky-bucket

A token-based rate limiter based on the leaky bucket algorithm.
Apache License 2.0
93 stars 10 forks source link

Add api try_acquire_or_balance #33

Closed niks3089 closed 2 months ago

niks3089 commented 5 months ago

Try acquire api returns a Boolean if the number of requests are allowed or not. Would good to have an option to try and acquire whatever the balance is if the number of requests can't be met.

udoprog commented 2 months ago

It requires coordination to do correctly. The point of the acquire method is to do this coordination and wait if necessary.