Documentation
¶
Overview ¶
Package resourcepool provides a small, reusable, homogeneous collection type with an attached (opaque) policy.
This package is intentionally "dumb": - It enforces homogeneity (all items share the same key). - It supports safe removal (Take) for single-use allocation patterns. - It does not evaluate policy or perform IO; higher-level code does that.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Keyed ¶
type Keyed[K comparable] interface { PoolKey() K }
Keyed is implemented by items that belong to a homogeneous pool.
type Pool ¶
type Pool[K comparable, R Keyed[K], P any] struct { Name string `json:"name" yaml:"name"` Key K `json:"key" yaml:"key"` Policy P `json:"policy" yaml:"policy"` Items []R `json:"items,omitempty" yaml:"items,omitempty"` }
Pool is a homogeneous collection of items identified by a key, plus an attached policy of caller-defined type.
Policy is opaque to this package: Pool carries it, but does not interpret it.
func (*Pool[K, R, P]) AddMany ¶
AddMany appends items if all satisfy the pool's homogeneity invariant.