...
Package semaphore
Overview ▹
Index ▹
Variables
ErrNoTickets is the error returned by Acquire when it could not acquire a ticket from the semaphore within the configured timeout.
var ErrNoTickets = errors.New("could not acquire semaphore ticket")
type Semaphore ¶
Semaphore implements the semaphore resiliency pattern
type Semaphore struct {
// contains filtered or unexported fields
}
▹ Example
func New ¶
func New(tickets int, timeout time.Duration) *Semaphore
New constructs a new Semaphore with the given ticket-count and timeout.
func (*Semaphore) Acquire ¶
func (s *Semaphore) Acquire() error
Acquire tries to acquire a ticket from the semaphore. If it can, it returns nil. If it cannot after "timeout" amount of time, it returns ErrNoTickets. It is safe to call Acquire concurrently on a single Semaphore.
func (*Semaphore) Release ¶
func (s *Semaphore) Release()
Release releases an acquired ticket back to the semaphore. It is safe to call Release concurrently on a single Semaphore. It is an error to call Release on a Semaphore from which you have not first acquired a ticket.