goPool

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

通用协程池任务执行器实现 协程池,用以使用固定数量的 goroutine 顺序处理大量事件的场景

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	sync.Mutex     //互斥锁
	sync.WaitGroup //计数器,goroutine的个数
	// contains filtered or unexported fields
}

goroutine pool

func FromRunner

func FromRunner(capa int, runner Runner) *Pool

func NewPool

func NewPool(capa int,
	run func() (interface{}, error),
	quit func(*Pool, interface{}, error)) *Pool

func (*Pool) AddExecutor

func (this *Pool) AddExecutor()

手动创建pool执行器 add goroutine manual

func (*Pool) AutoKeepalive

func (this *Pool) AutoKeepalive(duration time.Duration)

自动保持active状态

func (*Pool) Count

func (this *Pool) Count() int

count may great then capa when user AddExecutor

func (*Pool) Keepalive

func (this *Pool) Keepalive() int

check alive 检查pool是否是激活状态

func (*Pool) WaitAllQuit

func (this *Pool) WaitAllQuit()

return after all goroutine quit in pool 等待所有的goroutine退出

type Runner

type Runner interface {
	Run() (interface{}, error)
	Quit(*Pool, interface{}, error)
}

Jump to

Keyboard shortcuts

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