sync

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPoolClosed = errors.New("pool is closed")
	ErrPoolFull   = errors.New("pool is full")
)

Functions

This section is empty.

Types

type CappedPool

type CappedPool[V any] struct {
	New    func() V
	Closer func(V)
	// contains filtered or unexported fields
}

CappedPool is a pool that will pool a limited number of values

func InitCappedPool

func InitCappedPool[V any](p *CappedPool[V], cap int) *CappedPool[V]

func NewCappedPool

func NewCappedPool[V any](cap int) *CappedPool[V]

func (*CappedPool[V]) Close

func (p *CappedPool[V]) Close()

func (*CappedPool[V]) Get

func (p *CappedPool[V]) Get(ctx context.Context) (v V, err error)

func (*CappedPool[V]) Put

func (p *CappedPool[V]) Put(v V) error

type ConcurrencyPool

type ConcurrencyPool[V any] struct {
	*CappedPool[V]

	// The minimum duration the Get can be blocked. The default is one second.
	BlockInterval time.Duration
	// contains filtered or unexported fields
}

func InitConcurrencyPool

func InitConcurrencyPool[V any](p *CappedPool[V], cap int) *ConcurrencyPool[V]

func NewConcurrencyPool

func NewConcurrencyPool[V any](cap int) *ConcurrencyPool[V]

func (*ConcurrencyPool[V]) Get

func (p *ConcurrencyPool[V]) Get(ctx context.Context) (v V, err error)

func (*ConcurrencyPool[V]) Put

func (p *ConcurrencyPool[V]) Put(v V) error

func (*ConcurrencyPool[V]) Release

func (p *ConcurrencyPool[V]) Release(v V)

type NilPool

type NilPool[V any] struct {
	New    func() V
	Closer func(V)
}

func (*NilPool[V]) Close

func (p *NilPool[V]) Close()

func (*NilPool[V]) Get

func (p *NilPool[V]) Get(_ context.Context) (v V, err error)

func (*NilPool[V]) Put

func (p *NilPool[V]) Put(v V) error

func (*NilPool[V]) Release

func (p *NilPool[V]) Release(v V)

type Pool

type Pool[V any] interface {
	// Get returns a value qualifies specified filter from the pool.
	Get(context.Context) (V, error)

	// Put puts a function back to the pool.
	Put(V) error

	// Close closes the pool.
	Close()
}

Pool defines a pool that supports eviction awareness and get value by specified filters.

type WaitGroup

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

func (*WaitGroup) Add

func (wg *WaitGroup) Add(delta int)

func (*WaitGroup) Done

func (wg *WaitGroup) Done()

func (*WaitGroup) IsWaiting

func (wg *WaitGroup) IsWaiting() bool

func (*WaitGroup) Reset

func (wg *WaitGroup) Reset()

type WaitPool

type WaitPool[V any] interface {
	Pool[V]

	// Release releases the quota occupied by a pooling value.
	Release(V)
}

WaitPool defines a pool that has limited capacity and will wait for a value to be returned if the pool is full.

Jump to

Keyboard shortcuts

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