Semaphore pattern implementation with timeout of lock/unlock operations.
The master is a feature frozen branch for versions 4.3.x and no longer maintained.
$ dep ensure -add github.com/kamilsk/[email protected]
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/[email protected]
The v5 branch is an actual development branch.
$ go get -u github.com/kamilsk/semaphore/v5
$ dep ensure -add github.com/kamilsk/[email protected]
Version v5.x.y focused on integration with the 🚧 breaker and the 🧰 platform packages.
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))
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
See more details here.
$ go get github.com/kamilsk/semaphore
$ # or use mirror
$ egg bitbucket.org/kamilsk/semaphore
This library is using SemVer for versioning, and it is not BC-safe.
1 The project is still in prototyping. ↩
made with ❤️ by OctoLab