gate

package
v0.0.0-...-b34ddb9 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package gate provides building blocks to limit concurrency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gate

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

Gate provides concurrency limitation.

func New

func New(maxInflight, maxWait int) *Gate

New creates a Gate.

func (*Gate) Reserve

func (g *Gate) Reserve() (*Reservation, bool)

Reserve attempts to obtain a reservation. If the wait queue is too long, it returns false.

type Reservation

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

Reservation represents a reservation.

func (*Reservation) Release

func (r *Reservation) Release()

Release returns the reservation. It must be called when the reservation is no longer needed. It doesn't matter if Wait() was called or not.

func (*Reservation) Wait

func (r *Reservation) Wait()

Wait blocks until number of inflight requests is lower than the maximum.

Jump to

Keyboard shortcuts

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