ratelimit: go.uber.org/ratelimit Index | Files | Directories

package ratelimit

import "go.uber.org/ratelimit"


Package Files

mutexbased.go ratelimit.go

type Clock Uses

type Clock interface {
    Now() time.Time

Clock is the minimum necessary interface to instantiate a rate limiter with a clock or mock clock, compatible with clocks created using github.com/andres-erbsen/clock.

type Limiter Uses

type Limiter interface {
    // Take should block to make sure that the RPS is met.
    Take() time.Time

Limiter is used to rate-limit some process, possibly across goroutines. The process is expected to call Take() before every iteration, which may block to throttle the goroutine.

func New Uses

func New(rate int, opts ...Option) Limiter

New returns a Limiter that will limit to the given RPS.

func NewUnlimited Uses

func NewUnlimited() Limiter

NewUnlimited returns a RateLimiter that is not limited.

type Option Uses

type Option func(l *limiter)

Option configures a Limiter.

var WithoutSlack Option = withoutSlackOption

WithoutSlack is an option for ratelimit.New that initializes the limiter without any initial tolerance for bursts of traffic.

func WithClock Uses

func WithClock(clock Clock) Option

WithClock returns an option for ratelimit.New that provides an alternate Clock implementation, typically a mock Clock for testing.



Package ratelimit imports 5 packages (graph) and is imported by 21 packages. Updated 2019-12-05. Refresh now. Tools for package owners.