concurrency

package
v1.0.1-0...-f351835 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

CODE ATTRIBUTION: https://github.com/korovkin/limiter Modified to accept a parameter to the executed job

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 Limiter

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

Limiter object

func NewLimiter

func NewLimiter(limit int) *Limiter

NewLimiter allocates a new ConcurrencyLimiter

func (*Limiter) Execute

func (c *Limiter) Execute(job func(param interface{}), param interface{}) 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 (*Limiter) Wait

func (c *Limiter) 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