pool

package
v1.2.54 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 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 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