Documentation
¶
Index ¶
- type DynamicSemaphore
- func (s *DynamicSemaphore) Acquire(ctx context.Context) error
- func (s *DynamicSemaphore) IsFull() bool
- func (s *DynamicSemaphore) Release()
- func (s *DynamicSemaphore) SetSize(size int)
- func (s *DynamicSemaphore) TryAcquire() bool
- func (s *DynamicSemaphore) Used() int
- func (s *DynamicSemaphore) Waiters() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DynamicSemaphore ¶
type DynamicSemaphore struct {
// contains filtered or unexported fields
}
DynamicSemaphore is a semaphore that can be dynamically resized and allows FIFO blocking when full.
func NewDynamicSemaphore ¶
func NewDynamicSemaphore(size int) *DynamicSemaphore
func (*DynamicSemaphore) Acquire ¶
func (s *DynamicSemaphore) Acquire(ctx context.Context) error
Acquire acquires a permit from the sempahore, blocking until one is made available via Release or the ctx is Done. Blocking callers are unblocked in FIFO order as permits are released.
func (*DynamicSemaphore) IsFull ¶
func (s *DynamicSemaphore) IsFull() bool
func (*DynamicSemaphore) Release ¶
func (s *DynamicSemaphore) Release()
Release releases a permit which unblocks a waiter if one exists. Panics if called without a corresponding call to Acquire or TryAcqyure.
func (*DynamicSemaphore) SetSize ¶
func (s *DynamicSemaphore) SetSize(size int)
SetSize resizes the semaphore. If the size is increased, waiters will be unblocked as needed.
func (*DynamicSemaphore) TryAcquire ¶
func (s *DynamicSemaphore) TryAcquire() bool
TryAcquire acquires a permit if one is available, returning true, else returns false if no permits are available.
func (*DynamicSemaphore) Used ¶
func (s *DynamicSemaphore) Used() int
Used returns how many permits are currently in use.
func (*DynamicSemaphore) Waiters ¶
func (s *DynamicSemaphore) Waiters() int
Waiters returns how many callers are blocked waiting for permits.