workpool

package
v1.12.21 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: MIT Imports: 5 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

This section is empty.

Functions

This section is empty.

Types

type Logger added in v1.10.4

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

Logger log record interface

type LoggerFunc added in v1.10.7

type LoggerFunc func(...interface{})

LoggerFunc is a bridge between Logger and any third party logger.

func (LoggerFunc) Println added in v1.10.7

func (f LoggerFunc) Println(args ...interface{})

Println implements Logger interface.

type Option added in v1.10.4

type Option func(p *Pool)

Option func Option to change pool.

func WithEntryCap added in v1.10.7

func WithEntryCap(n int) Option

WithEntryNum task entry chan number.

func WithEntryCloseWait added in v1.10.7

func WithEntryCloseWait(d time.Duration) Option

WithEntryCloseWait close entry chan entryCloseWait time.

func WithExecInterval added in v1.10.7

func WithExecInterval(t time.Duration) Option

WithExecInterval interval time after each task is executed.

func WithJobCap added in v1.10.7

func WithJobCap(n int) Option

WithJobCap job chan number.

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 entryCloseWait time.

func WithWorkerCap added in v1.10.7

func WithWorkerCap(num int) Option

WithWorkerCap 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(opts ...Option) *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 workerCap 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