PriorityWorkerPool

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2020 License: BSD-2-Clause Imports: 3 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
}

pool := New("testPool", 100, 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

This section is empty.

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) 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