taskpool

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2019 License: MIT Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTaskPool = errors.New("naza.taskpool: fxxk")

Functions

func Go

func Go(task Task)

func Init

func Init(modOptions ...ModOption) error

func KillIdleWorkers

func KillIdleWorkers()

func Status

func Status() (idleWorkerNum int, busyWorkerNum int)

Types

type ModOption

type ModOption func(option *Option)

type Option

type Option struct {
	InitWorkerNum int // 创建池对象时,预先开启的worker(协程)数量,如果为0,则不预先开启
}

type Pool

type Pool interface {
	// 向池内放入任务
	Go(task Task)

	// 获取当前空闲worker和工作worker的数量。注意,这只是一个瞬时值
	Status() (idleWorkerNum int, busyWorkerNum int)

	// 关闭池内所有的空闲worker(协程)
	KillIdleWorkers()
}

func NewPool

func NewPool(modOptions ...ModOption) (Pool, error)

type Task

type Task func()

type Worker

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

func NewWorker

func NewWorker(p *pool) *Worker

func (*Worker) Go

func (w *Worker) Go(task Task)

func (*Worker) Start

func (w *Worker) Start()

func (*Worker) Stop

func (w *Worker) Stop()

Jump to

Keyboard shortcuts

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