Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Mar 8, 2024
1 parent 11b1d3b commit 447634f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/projectdiscovery/ratelimit

go 1.19
go 1.21

require (
github.com/projectdiscovery/utils v0.0.82
Expand Down
10 changes: 3 additions & 7 deletions ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ func (limiter *Limiter) Stop() {
func New(ctx context.Context, max uint, duration time.Duration) *Limiter {
internalctx, cancel := context.WithCancel(context.TODO())

var maxCount atomic.Uint32
maxCount := &atomic.Uint32{}
maxCount.Store(uint32(max))
limiter := &Limiter{
maxCount: maxCount,
ticker: time.NewTicker(duration),
tokens: make(chan struct{}),
ctx: ctx,
cancelFunc: cancel,
}
limiter.maxCount.Store(uint32(max))
limiter.count.Store(uint32(max))
go limiter.run(internalctx)

Expand All @@ -98,17 +98,13 @@ func New(ctx context.Context, max uint, duration time.Duration) *Limiter {
// NewUnlimited create a bucket with approximated unlimited tokens
func NewUnlimited(ctx context.Context) *Limiter {
internalctx, cancel := context.WithCancel(context.TODO())

var maxCount atomic.Uint32
maxCount.Store(math.MaxUint32)

limiter := &Limiter{
maxCount: maxCount,
ticker: time.NewTicker(time.Millisecond),
tokens: make(chan struct{}),
ctx: ctx,
cancelFunc: cancel,
}
limiter.maxCount.Store(math.MaxUint32)
limiter.count.Store(math.MaxUint32)
go limiter.run(internalctx)

Expand Down

0 comments on commit 447634f

Please sign in to comment.