Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 (*Parallel[T]) Enqueue ¶ added in v1.2.56
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
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
Start pool with processor function to be called for any object 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