syncutil

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Unlicense Imports: 3 Imported by: 4

Documentation

Overview

Package syncutil contains extensions and utilities for package sync from the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChanSemaphore added in v0.18.1

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

ChanSemaphore is a channel-based semaphore.

It must be initialized with NewChanSemaphore.

func NewChanSemaphore added in v0.18.1

func NewChanSemaphore(maxRes uint) (c *ChanSemaphore)

NewChanSemaphore returns a new *ChanSemaphore with the provided maximum resource number.

func (*ChanSemaphore) Acquire added in v0.18.1

func (c *ChanSemaphore) Acquire(ctx context.Context) (err error)

Acquire implements the Semaphore interface for *ChanSemaphore.

func (*ChanSemaphore) Release added in v0.18.1

func (c *ChanSemaphore) Release()

Release implements the Semaphore interface for *ChanSemaphore.

type EmptySemaphore added in v0.18.1

type EmptySemaphore struct{}

EmptySemaphore is a semaphore that has no limit.

func (EmptySemaphore) Acquire added in v0.18.1

func (EmptySemaphore) Acquire(_ context.Context) (err error)

Acquire implements the Semaphore interface for EmptySemaphore. It always returns nil.

func (EmptySemaphore) Release added in v0.18.1

func (EmptySemaphore) Release()

Release implements the Semaphore interface for EmptySemaphore.

type OnceConstructor added in v0.27.0

type OnceConstructor[K comparable, V any] struct {
	// contains filtered or unexported fields
}

OnceConstructor initializes a value for one key only once.

TODO(a.garipov): Add benchmarks.

func NewOnceConstructor added in v0.27.0

func NewOnceConstructor[K comparable, V any](newFunc func(k K) (v V)) (c *OnceConstructor[K, V])

NewOnceConstructor returns a new properly initialized *OnceConstructor that uses newFunc to construct a value for the given key.

func (*OnceConstructor[K, V]) Get added in v0.27.0

func (c *OnceConstructor[K, V]) Get(key K) (v V)

Get returns a value for the given key. If a value isn't available, it waits until it is.

type Pool

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

Pool is the strongly typed version of sync.Pool that manages pointers to T.

func NewPool

func NewPool[T any](newFunc func() (v *T)) (p *Pool[T])

NewPool returns a new strongly typed pool. newFunc must not be nil.

func NewSlicePool

func NewSlicePool[T any](l int) (p *Pool[[]T])

NewSlicePool is a helper for constructing pools with pointers to slices of a type with the given length.

func (*Pool[T]) Get

func (p *Pool[T]) Get() (v *T)

Get selects an arbitrary item from the pool, removes it from the pool, and returns it to the caller.

See sync.Pool.Get.

func (*Pool[T]) Put

func (p *Pool[T]) Put(v *T)

Put adds v to the pool.

See sync.Pool.Put.

type Semaphore added in v0.18.1

type Semaphore interface {
	// Acquire gets the resource, will block until the resource can be acquired.
	// ctx is used for cancellation.
	Acquire(ctx context.Context) (err error)

	// Release the resource, never blocks.
	Release()
}

Semaphore is the semaphore interface.

Jump to

Keyboard shortcuts

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