pool

package
v0.0.0-...-0236cb5 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BindFunc

type BindFunc func(Job, chan Job) error

BindFunc is called to bind the output of one pool to the input of another

type Job

type Job interface {
	Execute()
}

Job defined an interface to allow worker pools to perform different kinds of work so long as the passed struct conforms to the Job interface

type PipedPool

type PipedPool struct {
	Config     PipedPoolConfig
	WorkInput  chan Job  // For client to send work to
	WorkOutput chan Job  // For workers to send jobs to after completion
	BinderEnd  chan bool // Used to notify binder the pool is stopping
	End        chan bool
	Workers    []PipedWorker

	WorkerChannel chan chan Job
	// contains filtered or unexported fields
}

PipedPool will start a pool of workers and dispatch jobs to them

func NewPipedPool

func NewPipedPool(cfg PipedPoolConfig) *PipedPool

NewPipedPool will return a configured PipedPool. You must call Start() to begin processing jobs

func (*PipedPool) BindPool

func (wp *PipedPool) BindPool(inputChannel chan Job)

BindPool will bind the output of this pool with the input channel of another

func (*PipedPool) Start

func (wp *PipedPool) Start()

Start will start the job dispatcher

func (*PipedPool) Stop

func (wp *PipedPool) Stop()

Stop workers and then the PipedPool dispatcher

func (*PipedPool) Submit

func (wp *PipedPool) Submit(job Job)

Submit is syntax sugar for pushing a job into the input channel

type PipedPoolConfig

type PipedPoolConfig struct {
	Workers         int
	EnableOutput    bool
	BufferOutput    bool
	OutputBufferLen int
	BufferInput     bool
	InputBufferLen  int
}

PipedPoolConfig configures the pool

type PipedWorker

type PipedWorker struct {
	ID            int
	WorkerChannel chan chan Job

	WriteToOutChannel bool
	JobOutput         chan Job // Job Output Channel
	JobInput          chan Job // Job input channel
	End               chan bool
}

Worker is a goroutine that listens for work and processes incoming requests

func (*PipedWorker) Start

func (w *PipedWorker) Start()

Start worker

func (*PipedWorker) Stop

func (w *PipedWorker) Stop()

Stop worker

type Pool

type Pool struct {
	Config        PoolConfig
	WorkInput     chan Job // For client to send work to
	End           chan bool
	Workers       []Worker
	WorkerChannel chan chan Job
}

func NewPool

func NewPool(cfg PoolConfig) *Pool

NewPool will return a configured Pool. You must call Start() to begin processing jobs

func (*Pool) Start

func (p *Pool) Start()

Start will start the job dispatcher

func (*Pool) Stop

func (p *Pool) Stop()

Stop workers and then the workerpool dispatcher

func (*Pool) Submit

func (p *Pool) Submit(job Job)

Submit is syntax sugar for pushing a job into the input channel

type PoolConfig

type PoolConfig struct {
	Workers        int
	BufferInput    bool
	InputBufferLen int
}

type Worker

type Worker struct {
	ID            int
	WorkerChannel chan chan Job
	JobOutput     chan Job // Job Output Channel
	JobInput      chan Job // Job input channel
	End           chan bool
}

Worker is a goroutine that listens for work and processes incoming requests (Jobs)

func (*Worker) Start

func (w *Worker) Start()

Start worker

func (*Worker) Stop

func (w *Worker) Stop()

Stop worker

Jump to

Keyboard shortcuts

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