rate_go16.go 654 B

123456789101112131415161718192021
  1. // Copyright 2017 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build !go1.7
  5. package rate
  6. import "golang.org/x/net/context"
  7. // Wait is shorthand for WaitN(ctx, 1).
  8. func (lim *Limiter) Wait(ctx context.Context) (err error) {
  9. return lim.waitN(ctx, 1)
  10. }
  11. // WaitN blocks until lim permits n events to happen.
  12. // It returns an error if n exceeds the Limiter's burst size, the Context is
  13. // canceled, or the expected wait time exceeds the Context's Deadline.
  14. func (lim *Limiter) WaitN(ctx context.Context, n int) (err error) {
  15. return lim.waitN(ctx, n)
  16. }