gQueue

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

通过指定goroutine个数,实现task queue执行器 提交任务到tash chan中,然后不断从chan中取出task执行 结合官方的sync.WaitGroup计数信号等待执行完毕 go goroutine非抢占式的,通过runtime.Gosched()让出cpu给其他goroutine

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

func New

func New(number, total int) *Queue

创建一个任务队列实例

func (*Queue) Add

func (this *Queue) Add(task func() interface{})

添加任务

func (*Queue) SetFinishedCallback

func (this *Queue) SetFinishedCallback(callback func())

所有任务完成后,回调函数

func (*Queue) SetTaskCallback

func (this *Queue) SetTaskCallback(callback func(res interface{}))

设置单个任务执行后的回调函数

func (*Queue) Start

func (this *Queue) Start()

开始执行任务

Jump to

Keyboard shortcuts

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