syncx

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: ISC Imports: 1 Imported by: 0

Documentation

Overview

Package syncx contains useful synchronization primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lazy added in v0.4.3

type Lazy[T any] struct {
	// contains filtered or unexported fields
}

Lazy represents a lazily computed value.

func (*Lazy[T]) Get added in v0.4.3

func (l *Lazy[T]) Get(f func() T) T

Get returns T, calling f to compute it, if necessary.

func (*Lazy[T]) GetErr added in v0.4.3

func (l *Lazy[T]) GetErr(f func() (T, error)) (T, error)

GetErr returns T and an error, calling f to compute them, if necessary.

type LimitedWaitGroup

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

LimitedWaitGroup is a version of sync.WaitGroup that limits the number of concurrently working goroutines by using a buffered channel as a semaphore.

func NewLimitedWaitGroup

func NewLimitedWaitGroup(limit int) *LimitedWaitGroup

NewLimitedWaitGroup returns a new LimitedWaitGroup that limits the number of concurrently working goroutines to limit.

func (*LimitedWaitGroup) Add

func (lwg *LimitedWaitGroup) Add(delta int)

Add increments the counter of the LimitedWaitGroup by the specified delta. It blocks if the number of active goroutines reaches the concurrency limit.

func (*LimitedWaitGroup) Done

func (lwg *LimitedWaitGroup) Done()

Done decrements the counter of the LimitedWaitGroup by one and releases a slot in the semaphore, allowing another goroutine to start.

func (*LimitedWaitGroup) Wait

func (lwg *LimitedWaitGroup) Wait()

Wait blocks until the counter of the LimitedWaitGroup becomes zero.

type Protected added in v0.5.0

type Protected[T any] struct {
	// contains filtered or unexported fields
}

Protected provides synchronized access to a value of type T.

func Protect added in v0.5.0

func Protect[T any](val T) *Protected[T]

Protect wraps T into Protected.

func (*Protected[T]) Access added in v0.5.0

func (p *Protected[T]) Access(f func(T))

Access provides write access to the protected value. It executes the provided function f with the value under a write lock.

func (*Protected[T]) RAccess added in v0.5.0

func (p *Protected[T]) RAccess(f func(T))

RAccess provides read access to the protected value. It executes the provided function f with the value under a read lock.

Jump to

Keyboard shortcuts

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