gqueue

package
v1.11.25 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

package gqueue 通过指定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

New 创建一个任务队列实例

func (*Queue) Add

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

Add 添加任务

func (*Queue) SetFinishedCallback

func (q *Queue) SetFinishedCallback(callback func())

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

func (*Queue) SetTaskCallback

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

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

func (*Queue) Start

func (q *Queue) Start()

Start 开始执行任务

Jump to

Keyboard shortcuts

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