Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/limits/limiters/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ package limiters

import (
"context"
"errors"
"sync"
"time"
)

var ErrBucketSetFull = errors.New("limiters: Bucket set is full")

// BucketSet combines a group of Ls into a single key-indexed structure.
// Basically, each unique key gets its own counter. The main use case for
// BucketSet is to apply per-resource rate limiting.
Expand Down Expand Up @@ -125,6 +128,9 @@ func (r *BucketSet) Take(key string) bool {
}

bucket := r.take(key)
for bucket == nil {
return false
}
return bucket.Take()
}

Expand All @@ -149,5 +155,9 @@ func (r *BucketSet) TakeContext(ctx context.Context, key string) error {
}

bucket := r.take(key)
if bucket == nil {
return ErrBucketSetFull
}

return bucket.TakeContext(ctx)
}
Loading