udoprog / leaky-bucket

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

Add api try_acquire_or_balance #33

Closed niks3089 closed 2 days ago

niks3089 commented 3 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 days ago

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