grpool

package
Version: v1.16.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package grpool implements a goroutine reusable pool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(f func()) error

Add pushes a new job to the pool using default goroutine pool. The job will be executed asynchronously.

func AddWithRecover

func AddWithRecover(userFunc func(), recoverFunc ...func(err error)) error

AddWithRecover pushes a new job to the pool with specified recover function. The optional <recoverFunc> is called when any panic during executing of <userFunc>. If <recoverFunc> is not passed or given nil, it ignores the panic from <userFunc>. The job will be executed asynchronously.

func Jobs

func Jobs() int

Jobs returns current job count of default goroutine pool.

func Size

func Size() int

Size returns current goroutine count of default goroutine pool.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Goroutine Pool

func New

func New(limit ...int) *Pool

New creates and returns a new goroutine pool object. The parameter <limit> is used to limit the max goroutine count, which is not limited in default.

func (*Pool) Add

func (p *Pool) Add(f func()) error

Add pushes a new job to the pool. The job will be executed asynchronously.

func (*Pool) AddWithRecover

func (p *Pool) AddWithRecover(userFunc func(), recoverFunc ...func(err error)) error

AddWithRecover pushes a new job to the pool with specified recover function. The optional <recoverFunc> is called when any panic during executing of <userFunc>. If <recoverFunc> is not passed or given nil, it ignores the panic from <userFunc>. The job will be executed asynchronously.

func (*Pool) Cap

func (p *Pool) Cap() int

Cap returns the capacity of the pool. This capacity is defined when pool is created. It returns -1 if there's no limit.

func (*Pool) Close

func (p *Pool) Close()

Close closes the goroutine pool, which makes all goroutines exit.

func (*Pool) IsClosed

func (p *Pool) IsClosed() bool

IsClosed returns if pool is closed.

func (*Pool) Jobs

func (p *Pool) Jobs() int

Jobs returns current job count of the pool. Note that, it does not return worker/goroutine count but the job/task count.

func (*Pool) Size

func (p *Pool) Size() int

Size returns current goroutine count of the pool.

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