mirror of
https://gitee.com/johng/gf
synced 2026-06-30 02:51:56 +08:00
23 lines
793 B
Markdown
23 lines
793 B
Markdown
semaphore
|
|
=========
|
|
|
|
[](https://travis-ci.org/eapache/go-resiliency)
|
|
[](https://godoc.org/github.com/eapache/go-resiliency/semaphore)
|
|
[](https://eapache.github.io/conduct.html)
|
|
|
|
The semaphore resiliency pattern for golang.
|
|
|
|
Creating a semaphore takes two parameters:
|
|
- ticket count (how many tickets to give out at once)
|
|
- timeout (how long to wait for a ticket if none are currently available)
|
|
|
|
```go
|
|
sem := semaphore.New(3, 1*time.Second)
|
|
|
|
if err := sem.Acquire(); err != nil {
|
|
// could not acquire semaphore
|
|
return err
|
|
}
|
|
defer sem.Release()
|
|
```
|