goroutinepool

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

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