From f9fa507a7a53406dbe1297d1093de94414c4155e Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Wed, 13 Jun 2018 10:16:49 -0700 Subject: [PATCH] vendor: upgrade "golang.org/x/time" Signed-off-by: Gyuho Lee --- Gopkg.lock | 3 ++- vendor/golang.org/x/time/rate/rate.go | 24 +++++++++++++++++----- vendor/golang.org/x/time/rate/rate_go16.go | 21 +++++++++++++++++++ vendor/golang.org/x/time/rate/rate_go17.go | 21 +++++++++++++++++++ 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 vendor/golang.org/x/time/rate/rate_go16.go create mode 100644 vendor/golang.org/x/time/rate/rate_go17.go diff --git a/Gopkg.lock b/Gopkg.lock index 6721bfbec..eae21735c 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -318,9 +318,10 @@ version = "v0.3.0" [[projects]] + branch = "master" name = "golang.org/x/time" packages = ["rate"] - revision = "c06e80d9300e4443158a03817b8a8cb37d230320" + revision = "fbb02b2291d28baffd63558aa44b4b56f178d650" [[projects]] name = "google.golang.org/genproto" diff --git a/vendor/golang.org/x/time/rate/rate.go b/vendor/golang.org/x/time/rate/rate.go index f65729230..7228d97e9 100644 --- a/vendor/golang.org/x/time/rate/rate.go +++ b/vendor/golang.org/x/time/rate/rate.go @@ -6,7 +6,6 @@ package rate import ( - "context" "fmt" "math" "sync" @@ -213,8 +212,19 @@ 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 context.Context) (err error) { +func (lim *Limiter) wait(ctx contextContext) (err error) { return lim.WaitN(ctx, 1) } @@ -222,7 +232,7 @@ func (lim *Limiter) Wait(ctx context.Context) (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 context.Context, n int) (err error) { +func (lim *Limiter) waitN(ctx contextContext, 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) } @@ -243,8 +253,12 @@ func (lim *Limiter) WaitN(ctx context.Context, n int) (err error) { if !r.ok { return fmt.Errorf("rate: Wait(n=%d) would exceed context deadline", n) } - // Wait - t := time.NewTimer(r.DelayFrom(now)) + // Wait if necessary + delay := r.DelayFrom(now) + if delay == 0 { + return nil + } + t := time.NewTimer(delay) defer t.Stop() select { case <-t.C: diff --git a/vendor/golang.org/x/time/rate/rate_go16.go b/vendor/golang.org/x/time/rate/rate_go16.go new file mode 100644 index 000000000..6bab1850f --- /dev/null +++ b/vendor/golang.org/x/time/rate/rate_go16.go @@ -0,0 +1,21 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !go1.7 + +package rate + +import "golang.org/x/net/context" + +// Wait is shorthand for WaitN(ctx, 1). +func (lim *Limiter) Wait(ctx context.Context) (err error) { + return lim.waitN(ctx, 1) +} + +// WaitN blocks until lim permits n events to happen. +// 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. +func (lim *Limiter) WaitN(ctx context.Context, n int) (err error) { + return lim.waitN(ctx, n) +} diff --git a/vendor/golang.org/x/time/rate/rate_go17.go b/vendor/golang.org/x/time/rate/rate_go17.go new file mode 100644 index 000000000..f90d85f51 --- /dev/null +++ b/vendor/golang.org/x/time/rate/rate_go17.go @@ -0,0 +1,21 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.7 + +package rate + +import "context" + +// Wait is shorthand for WaitN(ctx, 1). +func (lim *Limiter) Wait(ctx context.Context) (err error) { + return lim.waitN(ctx, 1) +} + +// WaitN blocks until lim permits n events to happen. +// 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. +func (lim *Limiter) WaitN(ctx context.Context, n int) (err error) { + return lim.waitN(ctx, n) +}