New returns a new [Pool] for T, and will use fn to construct new Ts when the pool is empty.
(fn func() T)
| 38 | // New returns a new [Pool] for T, and will use fn to construct new Ts when |
| 39 | // the pool is empty. |
| 40 | func New[T any](fn func() T) *Pool[T] { |
| 41 | return &Pool[T]{ |
| 42 | pool: sync.Pool{ |
| 43 | New: func() any { |
| 44 | return fn() |
| 45 | }, |
| 46 | }, |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // Get gets a T from the pool, or creates a new one if the pool is empty. |
| 51 | func (p *Pool[T]) Get() T { |
no outgoing calls