Properly handle different attachment use cases

This commit is contained in:
Philipp Heckel 2022-01-08 15:47:08 -05:00
parent cefe276ce5
commit 44a9509cd6
7 changed files with 202 additions and 75 deletions

View file

@ -29,12 +29,11 @@ func NewLimiter(limit int64) *Limiter {
func (l *Limiter) Add(n int64) error {
l.mu.Lock()
defer l.mu.Unlock()
if l.value+n <= l.limit {
l.value += n
return nil
} else {
if l.value+n > l.limit {
return ErrLimitReached
}
l.value += n
return nil
}
// Sub subtracts a value from the limiters internal value