syncutil

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 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 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