|
|
@@ -6,6 +6,7 @@
|
|
|
package rate
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
"fmt"
|
|
|
"math"
|
|
|
"sync"
|
|
|
@@ -212,19 +213,8 @@ func (lim *Limiter) ReserveN(now time.Time, n int) *Reservation {
|
|
|
return &r
|
|
|
}
|
|
|
|
|
|
-// contextContext is a temporary(?) copy of the context.Context type
|
|
|
-// to support both Go 1.6 using golang.org/x/net/context and Go 1.7+
|
|
|
-// with the built-in context package. If people ever stop using Go 1.6
|
|
|
-// we can remove this.
|
|
|
-type contextContext interface {
|
|
|
- Deadline() (deadline time.Time, ok bool)
|
|
|
- Done() <-chan struct{}
|
|
|
- Err() error
|
|
|
- Value(key interface{}) interface{}
|
|
|
-}
|
|
|
-
|
|
|
// Wait is shorthand for WaitN(ctx, 1).
|
|
|
-func (lim *Limiter) wait(ctx contextContext) (err error) {
|
|
|
+func (lim *Limiter) Wait(ctx context.Context) (err error) {
|
|
|
return lim.WaitN(ctx, 1)
|
|
|
}
|
|
|
|
|
|
@@ -232,7 +222,7 @@ func (lim *Limiter) wait(ctx contextContext) (err error) {
|
|
|
// It returns an error if n exceeds the Limiter's burst size, the Context is
|
|
|
// canceled, or the expected wait time exceeds the Context's Deadline.
|
|
|
// The burst limit is ignored if the rate limit is Inf.
|
|
|
-func (lim *Limiter) waitN(ctx contextContext, n int) (err error) {
|
|
|
+func (lim *Limiter) WaitN(ctx context.Context, n int) (err error) {
|
|
|
if n > lim.burst && lim.limit != Inf {
|
|
|
return fmt.Errorf("rate: Wait(n=%d) exceeds limiter's burst %d", n, lim.burst)
|
|
|
}
|