From bdec0f4121b71762b8d807711cd7a28b207ab747 Mon Sep 17 00:00:00 2001 From: Ben Parees Date: Fri, 3 Apr 2015 22:29:58 -0400 Subject: [PATCH] UPSTREAM: add a blocking accept method to RateLimiter https://github.com/GoogleCloudPlatform/kubernetes/pull/6314 --- .../GoogleCloudPlatform/kubernetes/pkg/util/throttle.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Godeps/_workspace/src/github.com/GoogleCloudPlatform/kubernetes/pkg/util/throttle.go b/Godeps/_workspace/src/github.com/GoogleCloudPlatform/kubernetes/pkg/util/throttle.go index 0b337c5e3c00..c961811faa85 100644 --- a/Godeps/_workspace/src/github.com/GoogleCloudPlatform/kubernetes/pkg/util/throttle.go +++ b/Godeps/_workspace/src/github.com/GoogleCloudPlatform/kubernetes/pkg/util/throttle.go @@ -24,6 +24,8 @@ import ( type RateLimiter interface { // CanAccept returns true if the rate is below the limit, false otherwise CanAccept() bool + // Accept returns once a token becomes available. + Accept() // Stop stops the rate limiter, subsequent calls to CanAccept will return false Stop() } @@ -73,6 +75,11 @@ func (t *tickRateLimiter) CanAccept() bool { } } +// Accept will block until a token becomes available +func (t *tickRateLimiter) Accept() { + <-t.tokens +} + func (t *tickRateLimiter) Stop() { close(t.stop) }