limiter

package
v0.0.0-...-fe3d589 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrencyLimiter

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

ConcurrencyLimiter object.

func NewConcurrencyLimiter

func NewConcurrencyLimiter(name string, limit int) *ConcurrencyLimiter

NewConcurrencyLimiter allocates a new ConcurrencyLimiter. This is useful for limiting the amount of functions running at once and is used to only allow a specific number of sessions to start at once.

func (*ConcurrencyLimiter) FreeTicket

func (c *ConcurrencyLimiter) FreeTicket(ticket int)

FreeTicket adds the ticket back into the queue.

func (*ConcurrencyLimiter) InProgress

func (c *ConcurrencyLimiter) InProgress() int32

InProgress returns how many tickets are being used.

func (*ConcurrencyLimiter) Wait

func (c *ConcurrencyLimiter) Wait() (ticket int)

Wait waits for a free ticket in the queue. Functions that call wait must defer FreeTicket with thee ticket ID.

type DurationLimiter

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

DurationLimiter represents something that will wait until the ratelimit. has cleared.

func NewDurationLimiter

func NewDurationLimiter(name string, limit int32, duration time.Duration) (bs *DurationLimiter)

NewDurationLimiter creates a DurationLimiter. This is useful for allowing a specific operation to run only X amount of times in a duration of Y.

func (*DurationLimiter) Lock

func (l *DurationLimiter) Lock()

Lock waits until there is an available slot in the Limiter.

func (*DurationLimiter) Reset

func (l *DurationLimiter) Reset()

Reset resets the resetsAt.

Jump to

Keyboard shortcuts

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