pool

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WorkerChannel = make(chan chan *Job)

Functions

This section is empty.

Types

type Collector

type Collector struct {
	Work chan *Job // receives jobs to send to workers
	End  chan bool // when receives bool stops workers
	// contains filtered or unexported fields
}

func StartDispatcher

func StartDispatcher(workerCount int64) Collector

func (Collector) GetStatistics

func (c Collector) GetStatistics() *JobStatistics

func (Collector) Waiting

func (c Collector) Waiting() int

type Job

type Job struct {
	Data    interface{}
	JobFunc JobFunc
}

type JobFunc

type JobFunc func(id int64, data interface{})

type JobStatistics

type JobStatistics struct {
	Executing int64 // Total number of jobs executed
	Total     int64
}

type Queue

type Queue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue() *Queue

func (*Queue) Close

func (e *Queue) Close()

func (*Queue) Len

func (e *Queue) Len() int

获取队列长度

func (*Queue) Pop

func (e *Queue) Pop() (v interface{})

Pop 取出队列,(阻塞模式)

func (*Queue) Push

func (e *Queue) Push(v interface{})

func (*Queue) TryPop

func (e *Queue) TryPop() (v interface{}, ok bool)

试着取出队列(非阻塞模式)返回ok == false 表示空

func (*Queue) Wait

func (e *Queue) Wait()

Wait 等待队列消费完成

type Worker

type Worker struct {
	ID            int64
	WorkerChannel chan chan *Job // used to communicate between dispatcher and workers
	Channel       chan *Job
	End           chan struct{}
	// contains filtered or unexported fields
}

func (*Worker) Start

func (w *Worker) Start()

start worker

func (*Worker) Stop

func (w *Worker) Stop()

end worker

Jump to

Keyboard shortcuts

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