Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stop method #20

Merged
merged 4 commits into from Dec 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions ratelimit.go
Expand Up @@ -68,6 +68,13 @@ func (ratelimiter *Limiter) SleepandReset(sleepTime time.Duration, newLimit uint
go ratelimiter.run(ctx)
}

// Stop the rate limiter canceling the internal context
func (ratelimiter *Limiter) Stop() {
if ratelimiter.cancelFunc != nil {
ratelimiter.cancelFunc()
}
}

// New creates a new limiter instance with the tokens amount and the interval
func New(ctx context.Context, max uint, duration time.Duration) *Limiter {
internalctx, cancel := context.WithCancel(context.TODO())
Expand Down