sync

package
v0.0.0-...-4a793a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2025 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL