workpool

package
v1.10.5 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2020 License: MIT Imports: 6 Imported by: 0

README

workpool

1.do some task in work pool.
2.Workpool handles large-scale asynchronous tasks or as a one-step task queue 
by specifying the number of workers and limiting the number of task entries.
3.Supports smooth exit of tasks.

How to use

please see pool_test.go

Documentation

Overview

Package workpool for do task in work pool.

Index

Constants

This section is empty.

Variables

View Source
var (

	// LogDebug log task run in which worker.
	LogDebug = false
)

Functions

This section is empty.

Types

type Logger added in v1.10.4

type Logger interface {
	Println(args ...interface{})
}

Logger log record interface

type Option added in v1.10.4

type Option func(p *Pool)

Option func Option to change pool

func WithLogger added in v1.10.4

func WithLogger(logEntry Logger) Option

WithLogger change logger entry.

func WithShutdownWait added in v1.10.4

func WithShutdownWait(d time.Duration) Option

WithShutdownWait change shutdown wait time.

func WithWaitTime added in v1.10.4

func WithWaitTime(d time.Duration) Option

WithWaitTime close entry chan wait time.

func WithWorkerNum added in v1.10.4

func WithWorkerNum(num int) Option

WithWorkerNum change worker num.

type Pool added in v1.10.4

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

Pool task work pool

func NewPool added in v1.10.4

func NewPool(num int, ec int, jc ...int) *Pool

NewPool returns a pool.

func (*Pool) AddTask added in v1.10.4

func (p *Pool) AddTask(t *Task)

AddTask add a task to p.entryChan.

func (*Pool) BatchAddTask added in v1.10.4

func (p *Pool) BatchAddTask(t []*Task)

BatchAddTask batch add task to p.entryChan.

func (*Pool) Run added in v1.10.4

func (p *Pool) Run()

Run create workerNum goroutine to exec task.

func (*Pool) Shutdown added in v1.10.4

func (p *Pool) Shutdown()

Shutdown If all task are sent to the task entry chan, you can call this method to exit smoothly.

type Task added in v1.10.4

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

Task task struct.

func NewTask added in v1.10.4

func NewTask(fn func() error) *Task

NewTask returns task,create a task entry.

Jump to

Keyboard shortcuts

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