limiter

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: MIT Imports: 0 Imported by: 4

README

go lang goroutine concurrency limiter

builds

Build Status

example

limit the number of concurrent go routines to 10:

  limit := limiter.New(10)
  for i := 0; i < 1000; i++ {
  	limit.Execute(func() {
  		// do some work
  	})
  }
  limit.Wait()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter chan struct{}

Limiter ...

func New

func New(limit int) Limiter

New instanciates a new Limiter limit: the max number of goroutines running at a time

func (Limiter) Execute

func (c Limiter) Execute(job func())

Execute will queue jobs, thanks to how channels work job: the function you want to be run on this limiter

func (Limiter) Wait

func (c Limiter) Wait()

Wait waits that all jobs are done Wait have to be called only once per instance

Jump to

Keyboard shortcuts

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