limiter

package
v1.7.9 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package limiter provides concurrency limiters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fixed

type Fixed chan struct{}

Fixed is a simple channel-based concurrency limiter. It uses a fixed size channel to limit callers from proceeding until there is a value available in the channel. If all are in-use, the caller blocks until one is freed.

func NewFixed

func NewFixed(limit int) Fixed

func (Fixed) Available added in v1.4.0

func (t Fixed) Available() int

Available returns the number of available tokens that may be taken.

func (Fixed) Capacity added in v1.4.0

func (t Fixed) Capacity() int

Capacity returns the number of tokens can be taken.

func (Fixed) Idle added in v1.4.0

func (t Fixed) Idle() bool

Idle returns true if the limiter has all its capacity is available.

func (Fixed) Release

func (t Fixed) Release()

Release releases a token back to the limiter.

func (Fixed) Take

func (t Fixed) Take()

Take attempts to take a token and blocks until one is available.

func (Fixed) TryTake added in v1.4.0

func (t Fixed) TryTake() bool

TryTake attempts to take a token and return true if successful, otherwise returns false.

type Rate added in v1.4.3

type Rate interface {
	WaitN(ctx context.Context, n int) error
	Burst() int
}

func NewRate added in v1.4.3

func NewRate(bytesPerSec, burstLimit int) Rate

type Writer added in v1.4.3

type Writer struct {
	// contains filtered or unexported fields
}

func NewWriter added in v1.4.3

func NewWriter(w io.WriteCloser, bytesPerSec, burstLimit int) *Writer

NewWriter returns a writer that implements io.Writer with rate limiting. The limiter use a token bucket approach and limits the rate to bytesPerSec with a maximum burst of burstLimit.

func NewWriterWithRate added in v1.4.3

func NewWriterWithRate(w io.WriteCloser, limiter Rate) *Writer

WithRate returns a Writer with the specified rate limiter.

func (*Writer) Close added in v1.4.3

func (s *Writer) Close() error

func (*Writer) Name added in v1.4.3

func (s *Writer) Name() string

func (*Writer) Sync added in v1.4.3

func (s *Writer) Sync() error

func (*Writer) Write added in v1.4.3

func (s *Writer) Write(b []byte) (int, error)

Write writes bytes from b.

Jump to

Keyboard shortcuts

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