epool

package module
v0.0.0-...-9a4c439 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

epool

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](workerCount int64) *Collector[T]

New New

func NewDefault

func NewDefault[T any]() *Collector[T]

NewDefault NewDefault(100)

func (*Collector[T]) AddJob

func (c *Collector[T]) AddJob(data T, f JobFunc[T])

func (*Collector[T]) GetStatistics

func (c *Collector[T]) GetStatistics() *JobStatistics

func (*Collector[T]) Stop

func (c *Collector[T]) Stop()

func (*Collector[T]) Waiting

func (c *Collector[T]) Waiting() int

type Job

type Job[T any] struct {
	Data    T
	JobFunc JobFunc[T]
}

type JobFunc

type JobFunc[T any] func(id int64, data T)

type JobStatistics

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

type Queue

type Queue[T any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue[T any]() *Queue[T]

NewQueue 创建队列

func (*Queue[T]) Close

func (e *Queue[T]) Close()

Close 关闭队列

func (*Queue[T]) Len

func (e *Queue[T]) Len() int

Len 获取队列长度

func (*Queue[T]) Pop

func (e *Queue[T]) Pop() (v T)

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

func (*Queue[T]) Push

func (e *Queue[T]) Push(v T)

Push 入队列

func (*Queue[T]) TryPop

func (e *Queue[T]) TryPop() (v T, ok bool)

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

func (*Queue[T]) Wait

func (e *Queue[T]) Wait()

Wait 等待队列消费完成

type Worker

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

func (*Worker[T]) Start

func (w *Worker[T]) Start()

Start worker

func (*Worker[T]) Stop

func (w *Worker[T]) Stop()

Stop end worker

Jump to

Keyboard shortcuts

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