Skip to content

Commit dcca62f

Browse files
authored
pool: Add NewFunc (#59)
1 parent 1a3d91b commit dcca62f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pool/pool.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ type Pool[T any] struct {
77
}
88

99
func New[T any]() *Pool[T] {
10-
return &Pool[T]{&sync.Pool{New: func() any { return new(T) }}}
10+
return NewFunc(func() *T { return new(T) })
11+
}
12+
13+
func NewFunc[T any](fn func() *T) *Pool[T] {
14+
return &Pool[T]{&sync.Pool{New: func() any { return fn() }}}
1115
}
1216

1317
func (p *Pool[T]) Get() *T {

0 commit comments

Comments
 (0)