pool

package
v0.9.14 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package pool provides a concurrency-safe pool of instances for libraries whose types are not safe for concurrent use. pgstream shares a single transformer per column across all snapshot worker goroutines, so transformers backed by stateful libraries (shared rng, internal buffers) hand out one underlying instance per concurrent caller instead of serializing calls with a lock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool hands out dedicated instances of T so that concurrent callers never share one. Instances are created lazily with the provided constructor and reused across calls once released.

func New

func New[T any](newFn func() (T, error)) (*Pool[T], error)

New returns a pool that creates instances with newFn. The constructor is invoked eagerly once so that invalid configuration fails at build time rather than on first use.

func (*Pool[T]) Acquire

func (p *Pool[T]) Acquire() (T, error)

Acquire returns an instance for exclusive use by the caller. It must be returned with Release once the caller is done with it, including any reads of buffers the instance owns.

func (*Pool[T]) Release

func (p *Pool[T]) Release(instance T)

Release returns an instance to the pool for reuse.

Jump to

Keyboard shortcuts

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