priorityworkerpool

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 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

import "github.com/kc596/priorityworkerpool"

const (
	poolName   = "testPool"
	numWorkers = 1000
)

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

pool := priorityworkerpool.New(poolName, numWorkers, panicHandler)

job := func() {
	// code to execute
}

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
ShutDown() void Delete queue and prevents pickup of next job from the queue

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