pool

package
v0.0.0-...-036eace Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2020 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DispatcherStatusStopped = iota
	DispatcherStatusRunning
)

Different status values for the dispatcher

Variables

View Source
var (
	// ErrJobQueueFull happens when jobs queue reaches its maximum size and a new job
	// needs to be attended
	ErrJobQueueFull = errors.New("Jobs queue is full")
	// ErrJobQueueClosed happens when job queue gets closed and a new job arrives
	ErrJobQueueClosed = errors.New("Jobs queue already closed")
)

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher struct {
	Queue *JobChannel
	// contains filtered or unexported fields
}

Dispatcher is the pool engine. Holds the queue receiving the jobs to be processed and holds the queue of available workers. When a job is received, takes the next available worker job channel and sends the job to it. Then that channel is read and processed by the corresponding worker

func NewDispatcher

func NewDispatcher(queueSize, poolSize int) *Dispatcher

NewDispatcher returns a new dispatcher with a new workers pool of the requested size

func (*Dispatcher) Start

func (d *Dispatcher) Start()

Start creates and starts all the workers until filling the pool

func (*Dispatcher) Stop

func (d *Dispatcher) Stop(closeQueue bool)

Stop stops the dispatcher

type DispatcherStatus

type DispatcherStatus int

DispatcherStatus type representing the current status of the dispatcher

type Job

type Job func()

Job the function representing the work to be processed by a worker

type JobChannel

type JobChannel struct {
	// contains filtered or unexported fields
}

JobChannel a channel to read or write jobs

func (*JobChannel) Close

func (c *JobChannel) Close()

Close closes the queue

func (*JobChannel) Push

func (c *JobChannel) Push(job Job) error

Push adds job to queue

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker represents the process executing a job

func NewWorker

func NewWorker(pool chan *Worker) *Worker

NewWorker returns a new worker instance

func (*Worker) Start

func (w *Worker) Start()

Start method starts the run loop for this worker

func (*Worker) Stop

func (w *Worker) Stop()

Stop signals the worker to stop listening for work requests and will block until the worker is stopped.

Jump to

Keyboard shortcuts

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