Documentation ¶
Overview ¶
Package pool provides a generic resource pool.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPoolClosed = errors.New("pgtest: pool closed")
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool[T any] struct { // contains filtered or unexported fields }
Pool is a generic resource pool.
As the intended use-case for the pool is to maintain resources used by test-cases running in parallel, for simplicity there is currently no maximum number of resources owned by the pool. The thinking being that the maximum number of resources should already be constrained by the '-parallel' flag passed to 'go test' (or GOMAXPROCS by default), so it's not clear if there's a use-case where we'd want to set a different limit. If such a use-case arrives we can always adjust this definition to allow a maxSize to be specified and default to GOMAXPROCS, but for now it is simpler to just let it grow as needed.
func New ¶
func New[T any](resourceConf *ResourceConf[T]) *Pool[T]
func (*Pool[T]) Acquire ¶
Acquire acquires the resource from the pool. This can either be a newly created resource, or a previously created idle resource.
func (*Pool[T]) Close ¶
Close cleans up the pool and prevents new resources from being acquired.
NOTE: for now we're just destroying ALL resources owned by the pool, not just the idle ones. This is primarily for simplicity, since the assumption is that pools will only be closed after all tests are done running. As a result, we can assume that nobody is using resources acquired from the pool when we close the pool. While this is likely not a valid assumption, since we probably want to allow for a graceful shutdown in certain cases, it seems better to stick with the simple approach for now then adjust as needed.
type Resource ¶
type Resource[T any] struct { // contains filtered or unexported fields }
A Resource is a resource maintained by a Pool.
func (*Resource[T]) Data ¶
func (r *Resource[T]) Data() T
Data returns the underlying data associated with the resource.