goroutinepool

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: AGPL-3.0 Imports: 5 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Usage: poolSize := 10 pool := goroutinepool.New(poolSize) pool.Start() pool.Go(func(){...}) // `Go' will return `NoMoreWorkerErr' if no more worker available pool.MustGo(func(){...}) // `MustGo' will block until any worker available

pool.Stop() // `Stop' will block to wait all workers done

pool.Start() // and the same pool can be reused

Index

Constants

This section is empty.

Variables

View Source
var (
	NoMoreWorkerErr = errors.New("no more worker, pool is full")
	TimeoutErr      = errors.New("time out")
)

Functions

This section is empty.

Types

type GoroutinePool

type GoroutinePool struct {
	sync.WaitGroup // wait all workers stopped

	sync.RWMutex // protect 'running' and 'workers'
	// contains filtered or unexported fields
}

func New

func New(cap int) *GoroutinePool

func (*GoroutinePool) Go

func (p *GoroutinePool) Go(f func()) error

func (*GoroutinePool) GoWithTimeout

func (p *GoroutinePool) GoWithTimeout(f func(), timeout time.Duration) error

func (*GoroutinePool) MustGo

func (p *GoroutinePool) MustGo(f func())

func (*GoroutinePool) Start

func (p *GoroutinePool) Start()

func (*GoroutinePool) Statistics

func (p *GoroutinePool) Statistics() [2]int

return [<IDLE-worker-num>, <total-worker-num>]

func (*GoroutinePool) Stop

func (p *GoroutinePool) Stop()

block until all workers stopped

Jump to

Keyboard shortcuts

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