workpool

package
v0.0.0-...-1272ae6 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Instance

func Instance()

Types

type Pool

type Pool struct {
	EntryChan chan *Task

	WorkerNum int

	JobsChan chan *Task
}

func NewPool

func NewPool(cap int) *Pool

返回一个协程池 @param cap 协程池中Goroutine的数量

func (*Pool) Run

func (this *Pool) Run(ctx context.Context)

让协程池Pool开始工作 @param ctx 上下文

func (*Pool) Worker

func (this *Pool) Worker(workID int, ctx context.Context)

协程池创建一个worker并且开始工作 @param workID Goroutine编号 @param ctx 上下文

type Task

type Task struct {
	HandleFunc   func() error
	TaskInstance interface{}
	Wg           *sync.WaitGroup
}

WorkPool中执行的任务

func NewTask

func NewTask(task interface{}, wg *sync.WaitGroup, handleFunc func() error) *Task

返回一个任务 @param task 任务类型 @param HandleFunc 处理函数

func (*Task) Execute

func (this *Task) Execute()

Jump to

Keyboard shortcuts

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