syncutil

package
v0.55.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2025 License: AGPL-3.0 Imports: 2 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 is a counting semaphore.

func NewSemaphore

func NewSemaphore(n int) *Semaphore

NewSemaphore creates a new Semaphore with the given limit.

func (*Semaphore) Acquire

func (l *Semaphore) Acquire()

Acquire acquires the semaphore. If the semaphore is already at its limit, it will block until one is released.

func (*Semaphore) Available

func (l *Semaphore) Available() int

Available returns the number of available slots in the semaphore.

func (*Semaphore) Limit

func (l *Semaphore) Limit() int

Limit returns the limit of the semaphore.

func (*Semaphore) Release

func (l *Semaphore) Release()

Release releases the semaphore.

func (*Semaphore) Used

func (l *Semaphore) Used() int

Used returns the number of used slots in the semaphore.

type WaitGroup

type WaitGroup struct {
	// contains filtered or unexported fields
}

WaitGroup is a synchronization primitive that waits for a collection of goroutines to finish. It is similar to sync.WaitGroup but with a context.

func NewWaitGroup

func NewWaitGroup(ctx context.Context) *WaitGroup

NewWaitGroup creates a new WaitGroup instance.

func (*WaitGroup) Add

func (wg *WaitGroup) Add(delta int64)

Add adds delta, which may be negative, to the WaitGroup counter. If the counter becomes zero or less, the channel returned by Wait is closed.

func (*WaitGroup) Done

func (wg *WaitGroup) Done()

Done decrements the WaitGroup counter by one. If the counter becomes zero or less, the channel returned by Wait is closed.

func (*WaitGroup) Wait

func (wg *WaitGroup) Wait() <-chan struct{}

Wait returns a channel that is closed when the WaitGroup counter is zero or less.

Jump to

Keyboard shortcuts

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