Documentation
¶
Overview ¶
Package semaphore implements the semaphore resiliency pattern for Go.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNoTickets = errors.New("could not acquire semaphore ticket")
ErrNoTickets is the error returned by Acquire when it could not acquire a ticket from the semaphore within the configured timeout.
Functions ¶
This section is empty.
Types ¶
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore implements the semaphore resiliency pattern
Example ¶
sem := New(3, 1*time.Second) for i := 0; i < 10; i++ { go func() { if err := sem.Acquire(); err != nil { return //could not acquire semaphore } defer sem.Release() // do something semaphore-guarded }() }
Output:
func (*Semaphore) Acquire ¶
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.
Click to show internal directories.
Click to hide internal directories.