concurrency

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: GPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package concurrency provides utility functions for working with goroutines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentPool

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

ConcurrentPool implements a simple semaphore-like structure to limit the number of concurrent goroutines working together.

func NewConcurrentPool

func NewConcurrentPool(capacity uint) (*ConcurrentPool, error)

NewConcurrentPool creates a new ConcurrentPool with the specified capacity. It panics if the capacity is 0.

func (*ConcurrentPool) Lock

func (p *ConcurrentPool) Lock()

Lock acquires a lock from the pool, waiting if necessary until a slot becomes available. It increments the used count using the reserveSlot method.

func (*ConcurrentPool) Unlock

func (p *ConcurrentPool) Unlock()

Unlock releases a lock, making a slot available for other goroutines. It decrements the used count and sends a signal on the changeChan to notify waiting goroutines.

type LockedValue added in v0.5.0

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

func NewLockedValue added in v0.5.0

func NewLockedValue[T any](initial T) *LockedValue[T]

func (*LockedValue[T]) Get added in v0.5.0

func (lv *LockedValue[T]) Get() T

func (*LockedValue[T]) Operate added in v0.5.0

func (lv *LockedValue[T]) Operate(operator Operator[T])

func (*LockedValue[T]) Set added in v0.5.0

func (lv *LockedValue[T]) Set(newValue T)

type Operator added in v0.5.0

type Operator[T any] func(T) T

Jump to

Keyboard shortcuts

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