Documentation

Overview

    Package limiter implements a concurrency limiter with support for contexts.

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type Limiter

    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

      func New() *Limiter

        New creates a new limiter with 0 tokens.

        func (*Limiter) Acquire

        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

          func (l *Limiter) Release(n int)

            Release adds a number of tokens back into the limiter.

            type LimiterIfc

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

            Source Files