limiter

package
v0.0.1-really Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2019 License: Apache-2.0 Imports: 1 Imported by: 3 modules, 15 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL