tb icon indicating copy to clipboard operation
tb copied to clipboard

Consider adding an auto close option to Throttler

Open jfromaniello opened this issue 11 years ago • 3 comments

Given that:

If a Bucket (key, rate) doesn't exist yet, it is created.

and

You must call Close when you're done with the Throttler in order to not leak a go-routine and a system-timer.

Wouldn't be nice to have an option to auto close buckets once they are full for n ticks?

Thanks

jfromaniello avatar Dec 04 '14 17:12 jfromaniello

Hello,

I'm not entirely happy with the API I designed here. With that said, buckets aren't supposed to be Closed once they're full. Would you elucidate me on your use case?

tsenart avatar Dec 14 '14 11:12 tsenart

If you wanted to use this library to rate limit an API or something, say based on an IP address or some kind of unbound data (auth token or whatever), then memory is going to grow over time.

Having a method to reclaim memory if the bucket isn't used for a while would be useful.

silas avatar Jan 07 '15 02:01 silas

Unfortunately I currently don't have time to work on this library. I'd recommend building something on top of https://github.com/juju/ratelimit

tsenart avatar Jan 07 '15 12:01 tsenart