priorityworkerpool

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: BSD-2-Clause Imports: 4 Imported by: 0

README

Priority Worker Pool

Build Status codecov Go Report Card

A worker pool in GoLang which schedules job according to priority.

Installation

go get github.com/kc596/priorityworkerpool

Quickstart


var panicHandler = func(alias string, err interface{}) {
	fmt.Println(alias, err) // or use logger
}


const (
	poolName   = "testPool"
	numWorkers = 1000
)

pool := New(poolName, numWorkers, panicHandler)

for _, job := range jobs {  // jobs are slices of func()
	pool.Submit(job, 1+rand.Float64())
}

APIs

Method Return Type Description
New(name string, workers int, panicHandler func(alias string, err interface{}) *Pool Returns a new worker pool
Submit(job func(), priority float64) void Submit a new job to worker pool
WaitGroup() *sync.WaitGroup Returns waitgroup to wait for all jobs submitted to finish

Documentation

Index

Constants

View Source
const (
	AliasSubmitPanic    = "SubmitJob"
	AliasSchedulePanic  = "JobQueue"
	ErrSubmitOnShutDown = "Pool is shut down"
)

panic aliases and messages

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool is type for Worker Pool

func New

func New(name string, workers int, panicHandler func(alias string, err interface{})) *Pool

New creates a new worker pool to manage goroutines

func (*Pool) ShutDown added in v1.0.5

func (pool *Pool) ShutDown()

ShutDown prevents pickup of next job from the queue For stopping the already picked up work, use context

func (*Pool) Submit

func (pool *Pool) Submit(job func(), priority float64)

Submit a job to worker pool

func (*Pool) WaitGroup

func (pool *Pool) WaitGroup() *sync.WaitGroup

WaitGroup to wait for all jobs submitted to finish WARNING: would not wait if there are no jobs at the instant

Jump to

Keyboard shortcuts

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