semaphore

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

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 represents a custom semaphore with optional capacity.

func NewSemaphore

func NewSemaphore(initialCap int64) *Semaphore

NewSemaphore creates and initializes a new Semaphore with the specified initial capacity.

func (*Semaphore) Acquire

func (s *Semaphore) Acquire(n int64) error

Acquire acquires n units from the semaphore if the capacity is not unlimited.

func (*Semaphore) Release

func (s *Semaphore) Release(n int64)

Release releases n units back to the semaphore if the capacity is not unlimited.

func (*Semaphore) Resize

func (s *Semaphore) Resize(newCap int64) error

Resize adjusts the maximum capacity of the semaphore. Acquires or releases permits accordingly.

func (*Semaphore) TryAcquire

func (s *Semaphore) TryAcquire(n int64) bool

TryAcquire attempts to acquire n units from the semaphore without blocking if the capacity is not unlimited.

Jump to

Keyboard shortcuts

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