workerpool

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2018 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvaildWorkerCapacity = errors.New("nyn: worker capacity must > 0")

ErrInvaildWorkerCapacity 是设置了不正确的 worker 容量时返回的错误

Functions

This section is empty.

Types

type WorkerPool

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

WorkerPool 是 worker pool

func NewWorkerPool

func NewWorkerPool(workerCount int) (pool *WorkerPool)

NewWorkerPool 返回一个新的 WorkerPool

func (*WorkerPool) AddWorkIfCouldSync

func (pool *WorkerPool) AddWorkIfCouldSync(workProvider func() (work func())) bool

AddWorkIfCouldSync 在还能添加工作时, 添加 workProvider 所返回的工作. 返回能否添加工作 如果 workProvider 返回了 nil, 会视为 hang

func (*WorkerPool) NoMoreWorks

func (pool *WorkerPool) NoMoreWorks()

NoMoreWorks 告知 pool 没有更多任务

func (*WorkerPool) SetCapacity

func (pool *WorkerPool) SetCapacity(i int) (err error)

SetCapacity 设置 worker pool 的 worker 容量

func (*WorkerPool) SetLogger

func (pool *WorkerPool) SetLogger(logger logger.Logger)

SetLogger 设置 logger

func (*WorkerPool) WaitQuit

func (pool *WorkerPool) WaitQuit()

WaitQuit waits to quit

Jump to

Keyboard shortcuts

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