Closed kktsvetkov closed 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.
There are methods with almost exactly the same code in the different drivers -
limit()
andlimitSilently()
.You can pull these out into a trait and have that code reused, something like
LimitAware
; or you have a common abstract parent class (likeAbstractRateLimiter
) with those implemented there, and then in all of the driver implementations, you only do specific operations.