grpool

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package grpool implements a goroutine reusable pool.

Goroutine池, 用于goroutine复用,提升异步操作执行效率(避免goroutine限制,并节约内存开销). 需要注意的是,grpool提供给的公共池不提供关闭方法,自创建的池可以手动关闭掉。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(f func()) error

添加异步任务(使用默认的池对象)

func Jobs

func Jobs() int

查询当前等待处理的任务总数

func Size

func Size() int

查询当前goroutine总数

Types

type Pool

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

goroutine池对象

func New

func New(size ...int) *Pool

创建goroutine池管理对象, 参数用于限制限制最大的goroutine数量/线程数/worker数量,非必需参数,默认不做限制

func (*Pool) Add

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

添加异步任务

func (*Pool) Close

func (p *Pool) Close()

关闭池,所有的任务将会停止,此后继续添加的任务将不会被执行

func (*Pool) ForkWorker

func (p *Pool) ForkWorker()

创建新的worker执行任务

func (*Pool) Jobs

func (p *Pool) Jobs() int

查询当前等待处理的任务总数

func (*Pool) Size

func (p *Pool) Size() int

查询当前goroutine worker总数

Jump to

Keyboard shortcuts

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