Documentation ¶
Index ¶
- type Semaphore
- func (s *Semaphore) Acquire()
- func (s *Semaphore) AcquireContext(ctx context.Context, n int) bool
- func (s *Semaphore) AcquireMany(n int)
- func (s *Semaphore) AcquireWithin(n int, d time.Duration) bool
- func (s *Semaphore) AvailablePermits() int
- func (s *Semaphore) DrainPermits() int
- func (s *Semaphore) Release()
- func (s *Semaphore) ReleaseMany(n int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore is an implementation of semaphore.
func (*Semaphore) Acquire ¶
func (s *Semaphore) Acquire()
Acquire acquires one permit. If it is not available, the goroutine will block until it is available.
func (*Semaphore) AcquireContext ¶
AcquireContext is similar to AcquireMany() but takes a context. Returns true if successful or false if the context is done first.
func (*Semaphore) AcquireMany ¶
AcquireMany is similar to Acquire() but for many permits.
The number of permits acquired is at most the number of permits in the semaphore. i.e. if n = 5 and s was created with New(2), at most 2 permits will be acquired.
func (*Semaphore) AcquireWithin ¶
AcquireWithin is similar to AcquireMany() but cancels if duration elapses before getting the permits. Returns true if successful and false if timeout occurs.
func (*Semaphore) AvailablePermits ¶
AvailablePermits gives number of available unacquired permits.
func (*Semaphore) DrainPermits ¶
DrainPermits acquires all available permits and return the number of permits acquired.
func (*Semaphore) ReleaseMany ¶
ReleaseMany releases n permits.
The number of permits released is at most the number of permits in the semaphore. i.e. if n = 5 and s was created with New(2), at most 2 permits will be released.