From 195febe68b86df2cb53d416827be399d0a656efe Mon Sep 17 00:00:00 2001 From: Shawn Poulson <92753637+Baliedge@users.noreply.github.com> Date: Mon, 31 Oct 2022 05:51:29 -0400 Subject: [PATCH] Add `NewPoolCustom()` (#2) To provide for use case that requires customizations to `sync.Pool` configuration. --- pool.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pool.go b/pool.go index f1bdc22..d8f6d8a 100644 --- a/pool.go +++ b/pool.go @@ -23,6 +23,14 @@ func NewPool[T any]() *Pool[T] { } } +// NewPoolCustom builds an airmat.Pool that utilizes the user provided +// sync.Pool. The sync.Pool must generate *Mattress[T] values. +func NewPoolCustom[T any](pool *sync.Pool) *Pool[T] { + return &Pool[T]{ + sp: pool, + } +} + // Get selects an arbitrary Mattress from the Pool, removes it from the Pool, and returns it to the caller. // It might return a Slice with some data, but since it should be written by index it's not an issue. func (p *Pool[T]) Get() *Mattress[T] {