concurrency

package
Version: v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 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

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL