pool

package
v0.0.0-...-6bdff43 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(log Logger)

Types

type Logger

type Logger interface {
	Println(...interface{})
	Printf(string, ...interface{})
}

type Pool

type Pool struct {
	//母版函数
	Function func(interface{}) interface{}
	//Pool输入队列
	In chan interface{}
	//Pool输出队列s
	Out chan interface{}

	//启动协程等待时间
	Interval time.Duration
	//正在执行的任务清单
	JobsList *smap.SMap
	//jobs表示执行任务的通道用于作为队列,我们将任务从切片当中取出来,然后存放到通道当中,再从通道当中取出任务并执行。
	Jobs chan *Worker

	//提前结束标识符
	Done bool
	// contains filtered or unexported fields
}

func NewPool

func NewPool(threads int) *Pool

实例化工作池使用

func (*Pool) InDone

func (p *Pool) InDone()

结束输入信道

func (*Pool) NewTick

func (p *Pool) NewTick() string

生成工作票据

func (*Pool) OutDone

func (p *Pool) OutDone()

结束输出信道

func (*Pool) Run

func (p *Pool) Run()

执行工作池当中的任务

func (*Pool) RunBack

func (p *Pool) RunBack()

func (*Pool) Stop

func (p *Pool) Stop()

向各工作协程发送提前结束指令

func (*Pool) Threads

func (p *Pool) Threads() int

获取线程数

func (*Pool) Wait

func (p *Pool) Wait()

type Worker

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

创建worker,每一个worker抽象成一个可以执行任务的函数

func NewWorker

func NewWorker(f func(interface{}) interface{}) *Worker

通过NewTask来创建一个worker

func (*Worker) Run

func (t *Worker) Run(in interface{}) (interface{}, error)

执行worker

Jump to

Keyboard shortcuts

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