modulepackage
0.0.0-20190908153047-0bc1bfb4debd
Repository: https://github.com/etherlabsio/workerpool.git
Documentation: pkg.go.dev
# README
workerpool
Concurrency limiting goroutine pool. Limits the concurrency of task execution, not the number of tasks queued. Never blocks submitting tasks, no matter how many tasks are queued.
This implementation builds on ideas from the following:
- http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang
- http://nesv.github.io/golang/2014/02/25/worker-queues-in-go.html
Installation
To install this package, you need to setup your Go workspace. The simplest way to install the library is to run:
$ go get github.com/etherlabsio/workerpool
Example
package main
import (
"fmt"
"github.com/etherlabsio/workerpool"
)
func main() {
wp := workerpool.New(2)
requests := []string{"alpha", "beta", "gamma", "delta", "epsilon"}
for _, r := range requests {
r := r
wp.Submit(func() {
fmt.Println("Handling request:", r)
})
}
wp.StopWait()
}
Real world examples
The list of open source projects using worker pool can be found here
License
# Packages
Package pacer provides a utility to limit the rate at which concurrent
goroutines begin execution.
# Functions
New creates and starts a pool of worker goroutines.
# Structs
WorkerPool is a collection of goroutines, where the number of concurrent goroutines processing requests does not exceed the specified maximum.