Skip to content

🚦 Semaphore pattern implementation with timeout of lock/unlock operations.

License

Notifications You must be signed in to change notification settings

friendlydan/semaphore

 
 

Repository files navigation

🚦 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/[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.

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

About

🚦 Semaphore pattern implementation with timeout of lock/unlock operations.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 95.6%
  • Makefile 4.4%