🚦 Semaphore pattern implementation with timeout of lock/unlock operations.
Branch: v5
Clone or download
Latest commit df260e7 Feb 20, 2019

README.md

🚦 semaphore

Semaphore pattern implementation with timeout of lock/unlock operations.

Awesome Patreon GoDoc Research License

Important news

The master is a feature frozen branch for versions 4.3.x and no longer maintained.

$ dep ensure -add github.com/kamilsk/semaphore@4.3.1

The v4 branch is a continuation of the master branch for versions v4.4.x to better integration with Go Modules.

$ go get -u github.com/kamilsk/semaphore/v4@v4.3.1

The v5 branch is an actual development branch.

$ go get -u github.com/kamilsk/semaphore/v5

Version v5.x.y focused on integration with the 🚧 breaker and the 🧰 platform packages.

Usage

Quick start

limiter := semaphore.New(1000)

http.HandleFunc("/", func(rw http.ResponseWriter, _ *http.Request) {
	if _, err := limiter.Acquire(semaphore.WithTimeout(time.Minute)); err != nil {
		http.Error(rw, http.StatusText(http.StatusTooManyRequests), http.StatusTooManyRequests)
		return
	}
	defer limiter.Release()
	// handle request
})

log.Fatal(http.ListenAndServe(":80", nil))

Console tool for command execution in parallel

This example shows how to execute many console commands in parallel.

$ semaphore create 2
$ semaphore add -- docker build
$ semaphore add -- vagrant up
$ semaphore add -- ansible-playbook
$ semaphore wait --timeout=1m --notify

asciicast

See more details here.

Installation

$ go get github.com/kamilsk/semaphore
$ # or use mirror
$ egg bitbucket.org/kamilsk/semaphore

egg1 is an extended go get.

Update

This library is using SemVer for versioning, and it is not BC-safe.

1 The project is still in prototyping. ↩


Gitter @kamilsk @octolab

made with ❀️ by OctoLab