waitgroup

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package waitgroup Based upon sync.WaitGroup waitgroup adds the feature of limiting the maximum number of concurrently started routines.

It could for example be used to start multiples routines querying a database but without sending too much queries in order to not overload the given database.

Created by chenguolin 2019-08-06

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WaitGroup

type WaitGroup struct {
	Size int //maximun number of concurrently goroutines
	// contains filtered or unexported fields
}

WaitGroup has the same role and close to the same API as the Golang sync.WaitGroup but adds a limit of the amount of goroutines started concurrently.

func New

func New(limit int) WaitGroup

New creates a WaitGroup. The limit parameter is the maximum amount of goroutines which can be started concurrently.

func (*WaitGroup) Add

func (s *WaitGroup) Add()

Add increments the internal WaitGroup counter. It can be blocking if the limit of spawned goroutines has been reached.

func (*WaitGroup) Done

func (s *WaitGroup) Done()

Done decrements the SizedWaitGroup counter. See sync.WaitGroup documentation for more information.

func (*WaitGroup) Wait

func (s *WaitGroup) Wait()

Wait blocks until the SizedWaitGroup counter is zero. See sync.WaitGroup documentation for more information.

Jump to

Keyboard shortcuts

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