diff options
author | Wim <wim@42.be> | 2020-11-22 15:55:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-22 15:55:57 +0100 |
commit | 4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf (patch) | |
tree | 92d3b8d27cd35455eae7423e4d47aad67cc6a43b /vendor/github.com/shazow/rateio | |
parent | cbb46293ab670c1989bfcd9aae5d853223074038 (diff) | |
download | matterbridge-msglm-4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf.tar.gz matterbridge-msglm-4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf.tar.bz2 matterbridge-msglm-4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf.zip |
Update vendor (#1297)
Diffstat (limited to 'vendor/github.com/shazow/rateio')
-rw-r--r-- | vendor/github.com/shazow/rateio/limiter.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/vendor/github.com/shazow/rateio/limiter.go b/vendor/github.com/shazow/rateio/limiter.go index db5ae76c..a18ce3c1 100644 --- a/vendor/github.com/shazow/rateio/limiter.go +++ b/vendor/github.com/shazow/rateio/limiter.go @@ -7,7 +7,7 @@ import ( const minInt = -int(^uint(0)>>1) - 1 -// The error returned when the read rate exceeds our specification. +// ErrRateExceeded is the error returned when the read rate exceeds our specification. var ErrRateExceeded = errors.New("Read rate exceeded.") // Limiter is an interface for a rate limiter. @@ -27,7 +27,7 @@ type simpleLimiter struct { } // NewSimpleLimiter creates a Limiter that restricts a given number of bytes per frequency. -func NewSimpleLimiter(amount int, frequency time.Duration) Limiter { +func NewSimpleLimiter(amount int, frequency time.Duration) *simpleLimiter { return &simpleLimiter{ Amount: amount, Frequency: frequency, @@ -38,7 +38,7 @@ func NewSimpleLimiter(amount int, frequency time.Duration) Limiter { // SimpleLimiter but adds a grace period at the start of the rate // limiting where it allows unlimited bytes to be read during that // period. -func NewGracefulLimiter(amount int, frequency time.Duration, grace time.Duration) Limiter { +func NewGracefulLimiter(amount int, frequency time.Duration, grace time.Duration) *simpleLimiter { return &simpleLimiter{ Amount: amount, Frequency: frequency, @@ -60,3 +60,12 @@ func (limit *simpleLimiter) Count(n int) error { } return nil } + +// Delay returns a channel that can be used to block until next window +func (limit *simpleLimiter) Delay() <-chan time.Time { + waitTill := time.Now() + if limit.numRead >= limit.Amount { + waitTill = waitTill.Add(limit.Frequency) + } + return time.NewTimer(time.Until(waitTill)).C +} |