workpool

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 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

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

Logger log record interface

type LoggerFunc

type LoggerFunc func(...interface{})

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

func (LoggerFunc) Println

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

Println implements Logger interface.

type Option

type Option func(p *Pool)

Option func Option to change pool.

func WithEntryCap

func WithEntryCap(n int) Option

WithEntryNum task entry chan number.

func WithEntryCloseWait

func WithEntryCloseWait(d time.Duration) Option

WithEntryCloseWait close entry chan entryCloseWait time.

func WithExecInterval

func WithExecInterval(t time.Duration) Option

WithExecInterval interval time after each task is executed.

func WithJobCap

func WithJobCap(n int) Option

WithJobCap job chan number.

func WithLogger

func WithLogger(logEntry Logger) Option

WithLogger change logger entry.

func WithShutdownWait

func WithShutdownWait(d time.Duration) Option

WithShutdownWait change shutdown entryCloseWait time.

func WithWorkerCap

func WithWorkerCap(num int) Option

WithWorkerCap change worker num.

type Pool

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

Pool task work pool

func NewPool

func NewPool(opts ...Option) *Pool

NewPool returns a pool.

func (*Pool) AddTask

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

AddTask add a task to p.entryChan.

func (*Pool) BatchAddTask

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

BatchAddTask batch add task to p.entryChan.

func (*Pool) Run

func (p *Pool) Run()

Run create workerCap goroutine to exec task.

func (*Pool) Shutdown

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

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

Task task struct.

func NewTask

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