Properly handle different attachment use cases
This commit is contained in:
parent
cefe276ce5
commit
44a9509cd6
7 changed files with 202 additions and 75 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue