Skip to content

Commit

Permalink
io/ratelimit: allow new limiter with duration
Browse files Browse the repository at this point in the history
  • Loading branch information
5aaee9 committed Jul 6, 2023
1 parent 5289808 commit ef08fd0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkgs/io/ratelimit/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ func NewLimiter(size uint64) *Limiter {
}
}

// NewLimiter returns new limiter
func NewLimiterWithDuration(size uint64, duration time.Duration) *Limiter {
return &Limiter{
size: size,
now: 0,
duration: duration,
last: time.Now(),
}
}

// Wait allow you take data
func (l *Limiter) Wait(size uint64) {
if l.size == 0 {
Expand Down

0 comments on commit ef08fd0

Please sign in to comment.