mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 06:01:50 +00:00
add a blocking accept method to RateLimiter
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user