nikolaposa / rate-limit

🚔 General purpose rate limiter implementation.
MIT License
271 stars 47 forks source link

Pull out some of the duplicate code into traits or abstract parent #50

Closed kktsvetkov closed 3 years ago

kktsvetkov commented 3 years ago

There are methods with almost exactly the same code in the different drivers - limit() and limitSilently().

You can pull these out into a trait and have that code reused, something like LimitAware; or you have a common abstract parent class (like AbstractRateLimiter) with those implemented there, and then in all of the driver implementations, you only do specific operations.

nikolaposa commented 3 years ago

They are only seemingly the same. The main reason I decided to segregate interfaces into RateLimiter and SilentRateLimiter was that I wanted to make default one fast, atomic, with as little communication as possible with backend (eg. Redis). The two interfaces have different intentions, they will change for different reasons, therefore trying to keep things DRY between them is not the way to go.