semutil

package
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MPL-2.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 MultiSem

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

MultiSem is a semaphore that is made out of multiple underlying semaphores. The semaphores are attempted one at a time.

func (*MultiSem) Acquire

func (ms *MultiSem) Acquire(ctx context.Context, n int64) (ReleaseFun, error)

Acquire acquires a semaphore. If all semaphores are starved, it only blocks on the last semaphore.

func (*MultiSem) TryAcquire

func (ms *MultiSem) TryAcquire(n int64) (ReleaseFun, bool)

TryAcquire acquires a semaphore, but does not block.

type ReleaseFun

type ReleaseFun func()

ReleaseFun is a function that needs to be called to release the semaphore.

type Semaphore

type Semaphore interface {
	// Acquire acquires a resource on the semaphore. If no resource is available,
	// the call blocks until one is made available.
	Acquire(ctx context.Context, n int64) (ReleaseFun, error)
	// TryAcquire acquires a resource on the semaphore. If no resource is
	// available, the call returns immediately with false.
	TryAcquire(n int64) (ReleaseFun, bool)
}

Semaphore is a generic semaphore.

func NewMultiSem

func NewMultiSem(sems ...Semaphore) Semaphore

NewMultiSem creates a new MultiSem.

func NewWeighted

func NewWeighted(n int64) Semaphore

NewWeighted creates a new weighted semaphore.

type Weighted

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

Weighted is a weighted semaphore.

func (*Weighted) Acquire

func (w *Weighted) Acquire(ctx context.Context, n int64) (ReleaseFun, error)

Acquire acquires a semaphore.

func (*Weighted) TryAcquire

func (w *Weighted) TryAcquire(n int64) (ReleaseFun, bool)

TryAcquire acquires a semaphore, but does not block.

Jump to

Keyboard shortcuts

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