workerpool

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job interface {
	// JobName returns the name of the job.
	JobName() string

	// Hash returns a uint64 hash for a job.
	Hash() uint64

	// Run executes the job.
	Run()

	// GetDoneCh returns the channel, which when closed, indicates that the job was finished.
	GetDoneCh() <-chan struct{}
}

Job is a runnable interface to queue jobs on a WorkerPool

type WorkerPool

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

WorkerPool object representation

func NewWorkerPool

func NewWorkerPool(nWorkers int) *WorkerPool

NewWorkerPool creates a new work group. If nWorkers is 0, will poll goMaxProcs to get the number of routines to spawn. Reminder: routines are never pinned to system threads, it's up to the go scheduler to decide when and where these will be scheduled.

func (*WorkerPool) AddJob

func (wp *WorkerPool) AddJob(job Job) <-chan struct{}

AddJob posts the job on a worker queue Uses Hash underneath to choose worker to post the job to

func (*WorkerPool) AddJobRoundRobin

func (wp *WorkerPool) AddJobRoundRobin(jobs Job)

AddJobRoundRobin adds a job in round robin to the queues Concurrent calls to AddJobRoundRobin are thread safe and fair between each other

func (*WorkerPool) GetWorkerNumber

func (wp *WorkerPool) GetWorkerNumber() int

GetWorkerNumber get number of queues/workers

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

Stop stops the workerpool

Jump to

Keyboard shortcuts

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