A worker pool in GoLang which schedules job according to priority.
go get github.com/kc596/priorityworkerpool
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())
A complete example : Here
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 |