syncext

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

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

Go to latest
Published: Jan 29, 2026 License: Apache-2.0 Imports: 0 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 implements a counting semaphore: When multiple calls to its methods are made concurrently, only a maximum number of them may execute at the same time, and additional calls are made to wait until earlier ones finish.

This is most commonly used with expensive operations (either in terms of CPU or RAM) in order to avoid consuming all available resources or running into an OOM (Out Of Memory) error.

The implementation is based on <https://eli.thegreenplace.net/2019/on-concurrency-in-go-http-servers/>.

func NewSemaphore

func NewSemaphore(count int) *Semaphore

NewSemaphore creates a new semaphore that allows up to the given number of concurrent operations.

func (*Semaphore) Run

func (s *Semaphore) Run(action func())

Run executes the given function, ensuring that no more than the maximum number of ops for this semaphore execute concurrently.

func (*Semaphore) RunFallible

func (s *Semaphore) RunFallible(action func() error) (err error)

RunFallible is like Run, but allows the callback to return an error.

Jump to

Keyboard shortcuts

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