| 1 |
semaphore |
| 2 |
========= |
| 3 |
|
| 4 |
[](https://github.com/eapache/go-resiliency/actions/workflows/golang-ci.yml) |
| 5 |
[](https://godoc.org/github.com/eapache/go-resiliency/semaphore) |
| 6 |
[](https://eapache.github.io/conduct.html) |
| 7 |
|
| 8 |
The semaphore resiliency pattern for golang. |
| 9 |
|
| 10 |
Creating a semaphore takes two parameters: |
| 11 |
- ticket count (how many tickets to give out at once) |
| 12 |
- timeout (how long to wait for a ticket if none are currently available) |
| 13 |
|
| 14 |
```go |
| 15 |
sem := semaphore.New(3, 1*time.Second) |
| 16 |
|
| 17 |
if err := sem.Acquire(); err != nil { |
| 18 |
// could not acquire semaphore |
| 19 |
return err |
| 20 |
} |
| 21 |
defer sem.Release() |
| 22 |
``` |