Debian Codegraph @

semaphore/README.md

raw
1 semaphore
2 =========
3
4 [![Golang CI](https://github.com/eapache/go-resiliency/actions/workflows/golang-ci.yml/badge.svg)](https://github.com/eapache/go-resiliency/actions/workflows/golang-ci.yml)
5 [![GoDoc](https://godoc.org/github.com/eapache/go-resiliency/semaphore?status.svg)](https://godoc.org/github.com/eapache/go-resiliency/semaphore)
6 [![Code of Conduct](https://img.shields.io/badge/code%20of%20conduct-active-blue.svg)](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 ```