gopool

package module
v0.0.0-...-4ae6a83 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: MIT Imports: 9 Imported by: 0

README

gopool

A dynamically adjustable goroutine pool

warning

unfinished!!!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PoolFullErr  = errors.New("pool is full")
	PoolCloseErr = errors.New("pool is close")
)

Functions

This section is empty.

Types

type Job

type Job func(ctx context.Context)

It implements the runner interface.

func (Job) Run

func (f Job) Run(ctx context.Context)

function wrapper,implements the task interface.

type Monitor

type Monitor interface {
	Starve() int //饥饿的worker数
	Active() int //worker活跃数量
	Worker() int //当前worker的总数量
	Pool() int   //池的大小
	String() string
	Err() error
}

type Option

type Option func(*options)

func Log

func Log(w io.Writer) Option

func Queue

func Queue(n int) Option

func Skip

func Skip(b bool) Option

func Worker

func Worker(n int) Option

type Pool

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

func NewContextPool

func NewContextPool(ctx context.Context, opts ...Option) *Pool

func NewPool

func NewPool() *Pool

func (*Pool) Add

func (p *Pool) Add(ctx context.Context, j Job) error

添加一个任务

func (*Pool) Close

func (p *Pool) Close()

func (*Pool) Debug

func (p *Pool) Debug() (result map[string]interface{})

func (*Pool) Monitor

func (p *Pool) Monitor() Monitor

func (*Pool) Resize

func (p *Pool) Resize(size int) int

调整worker的大小 返回旧的worker数量

func (*Pool) SyncAdd

func (p *Pool) SyncAdd(ctx context.Context, j func(ctx2 context.Context)) error

添加一个任务同步

type Task

type Task interface {
	Run(ctx context.Context)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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