base: Index | Files

package limiter

import ""

Package limiter implements a concurrency limiter with support for contexts.


Package Files


type Limiter Uses

type Limiter struct {
    // contains filtered or unexported fields

A Limiter enforces concurrency limits among a set of goroutines. It maintains a bucket of tokens; a number of tokens (e.g., representing the cost of an operation) must be acquired by a goroutine before proceeding. A limiter is not fair: tokens are not granted in FIFO order; rather, waiters are picked randomly to be granted new tokens.

A nil limiter issues an infinite number of tokens.

func New Uses

func New() *Limiter

New creates a new limiter with 0 tokens.

func (*Limiter) Acquire Uses

func (l *Limiter) Acquire(ctx context.Context, need int) error

Acquire blocks until the goroutine is granted the desired number of tokens, or until the context is done.

func (*Limiter) Release Uses

func (l *Limiter) Release(n int)

Release adds a number of tokens back into the limiter.

type LimiterIfc Uses

type LimiterIfc interface {
    Release(n int)
    Acquire(ctx context.Context, need int) error

Package limiter imports 1 packages (graph) and is imported by 11 packages. Updated 2019-09-12. Refresh now. Tools for package owners.