pool

package
v1.2.97 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWorker

func NewWorker[T any](id int, readyPool chan chan Task[T], done *sync.WaitGroup) *worker[T]

Types

type Parallel added in v1.2.56

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

Parallel is a concurrency utility enable user to use the same processor (function) to process multiple objects in parallel using multiple workers. This utility is similar to WorkerPool but the main difference is that it is using the same function to reduce number of allocations

func NewParallel added in v1.2.56

func NewParallel[T any](maxWorkers int, capacity int) *Parallel[T]

func (*Parallel[T]) Enqueue added in v1.2.56

func (q *Parallel[T]) Enqueue(item T) bool

Enqueue submits a task to the buffered job queue without blocking, returns false if queue is full

func (*Parallel[T]) EnqueueWithTimeout added in v1.2.56

func (q *Parallel[T]) EnqueueWithTimeout(item T, timeout time.Duration) bool

EnqueueWithTimeout submits a task to the buffered job queue without blocking, returns false if queue is full within the duration

func (*Parallel[T]) Start added in v1.2.56

func (q *Parallel[T]) Start(processor func(T)) error

Start pool with processor function to be called for any object in the queue

func (*Parallel[T]) Submit added in v1.2.56

func (q *Parallel[T]) Submit(item T)

Submit a task to the job queue, blocked if no workers are available

func (*Parallel[T]) WaitAll added in v1.2.64

func (q *Parallel[T]) WaitAll()

WaitAll blocks until completion of all tasks in the queue

type Task

type Task[T any] interface {
	Run() T
}

Task is interface for any job executed by the worker pool

type WorkerPool

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

func NewWorkerPool

func NewWorkerPool[T any](maxWorkers int, capacity int) *WorkerPool[T]

func (*WorkerPool[T]) Enqueue added in v1.2.53

func (q *WorkerPool[T]) Enqueue(task Task[T]) bool

Enqueue submits a task to the buffered job queue without blocking, returns false if queue is full

func (*WorkerPool[T]) EnqueueWithTimeout added in v1.2.53

func (q *WorkerPool[T]) EnqueueWithTimeout(task Task[T], timeout time.Duration) bool

EnqueueWithTimeout submits a task to the buffered job queue without blocking, returns false if queue is full within the duration

func (*WorkerPool[T]) Start added in v1.2.53

func (q *WorkerPool[T]) Start(callback func(T)) error

Start pool with optional callback to be invoked on task completion

func (*WorkerPool[T]) Stop added in v1.2.53

func (q *WorkerPool[T]) Stop()

func (*WorkerPool[T]) Submit added in v1.2.53

func (q *WorkerPool[T]) Submit(task Task[T])

Submit a task to the job queue, blocked if no workers are available

Jump to

Keyboard shortcuts

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