Skip to content

gammazero/workers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

workers

simple worker pool

GoDoc Build Status codecov License

The workers package implements a simple fixed-size pool of goroutines for executing functions concurrently. The purpose is to limit concurrency to the number of goroutines in the pool.

When all workers are busy, the channel for submitting tasks blocks. If you are looking for a worker pool that never blocks when submitting tasks, see workerpool.

Installation

$ go get github.com/gammazero/workers

Example

package main

import (
	"fmt"
	"github.com/gammazero/workers"
)

func main() {
	do, done := workers.New(5)
	requests := []string{"alpha", "beta", "gamma", "delta", "epsilon"}

	for _, r := range requests {
		do <- func() {
			fmt.Println("Handling request:", r)
		}
	}
	close(do) // stop workers
	<-done    // wait for all workers to exit

	fmt.Println("All done")
}

About

simple worker pool to limit concurrency

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages