MCPcopy
hub / github.com/uber-go/zap / New

Function New

internal/pool/pool.go:40–48  ·  view source on GitHub ↗

New returns a new [Pool] for T, and will use fn to construct new Ts when the pool is empty.

(fn func() T)

Source from the content-addressed store, hash-verified

38// New returns a new [Pool] for T, and will use fn to construct new Ts when
39// the pool is empty.
40func 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.
51func (p *Pool[T]) Get() T {

Callers 9

error.goFile · 0.92
json_encoder.goFile · 0.92
console_encoder.goFile · 0.92
entry.goFile · 0.92
error.goFile · 0.92
TestNewFunction · 0.92
TestNew_RaceFunction · 0.92
stack.goFile · 0.92
NewPoolFunction · 0.92

Calls

no outgoing calls

Tested by 2

TestNewFunction · 0.74
TestNew_RaceFunction · 0.74