limiter

package
v0.0.0-...-b729584 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

README

korovkin/limiter

Documentation

Index

Constants

View Source
const (
	// DefaultLimit is the default concurrency limit
	DefaultLimit = 100
)

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(limit int) *ConcurrencyLimiter

NewConcurrencyLimiter allocates a new ConcurrencyLimiter

func (*ConcurrencyLimiter) Execute

func (c *ConcurrencyLimiter) Execute(job func()) int

Execute adds a function to the execution queue. if num of go routines allocated by this instance is < limit launch a new go routine to execute job else wait until a go routine becomes available

func (*ConcurrencyLimiter) ExecuteWithTicket

func (c *ConcurrencyLimiter) ExecuteWithTicket(job func(ticket int)) int

ExecuteWithTicket adds a job into an execution queue and returns a ticket id. if num of go routines allocated by this instance is < limit launch a new go routine to execute job else wait until a go routine becomes available

func (*ConcurrencyLimiter) GetNumInProgress

func (c *ConcurrencyLimiter) GetNumInProgress() int32

GetNumInProgress returns a (racy) counter of how many go routines are active right now

func (*ConcurrencyLimiter) Wait

func (c *ConcurrencyLimiter) Wait()

Wait will block all the previously Executed jobs completed running.

IMPORTANT: calling the Wait function while keep calling Execute leads to

un-desired race conditions

Jump to

Keyboard shortcuts

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