https://github.com/abiosoft/semaphore
Wrapping sync.Mutex for familiar semaphore api
https://github.com/abiosoft/semaphore
go golang mutex semaphore
Last synced: about 1 year ago
JSON representation
Wrapping sync.Mutex for familiar semaphore api
- Host: GitHub
- URL: https://github.com/abiosoft/semaphore
- Owner: abiosoft
- License: apache-2.0
- Created: 2012-09-18T12:02:07.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2024-08-18T08:36:24.000Z (almost 2 years ago)
- Last Synced: 2025-04-10T18:44:59.660Z (about 1 year ago)
- Topics: go, golang, mutex, semaphore
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 45
- Watchers: 3
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
semaphore
=========
Semaphore in Go
[](https://travis-ci.org/abiosoft/semaphore)
[](https://godoc.org/github.com/abiosoft/semaphore)
[](https://goreportcard.com/report/github.com/abiosoft/semaphore)
### Usage
Initiate
```go
import "github.com/abiosoft/semaphore"
...
sem := semaphore.New(5) // new semaphore with 5 permits
```
Acquire
```go
sem.Acquire() // one
sem.AcquireMany(n) // multiple
sem.AcquireWithin(n, time.Second * 5) // timeout after 5 sec
sem.AcquireContext(ctx, n) // acquire with context
```
Release
```go
sem.Release() // one
sem.ReleaseMany(n) // multiple
```
### documentation
http://godoc.org/github.com/abiosoft/semaphore