Skip to content

Commit

Permalink
pool: Add NewFunc (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshineplan committed Jun 13, 2024
1 parent 1a3d91b commit dcca62f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ type Pool[T any] struct {
}

func New[T any]() *Pool[T] {
return &Pool[T]{&sync.Pool{New: func() any { return new(T) }}}
return NewFunc(func() *T { return new(T) })
}

func NewFunc[T any](fn func() *T) *Pool[T] {
return &Pool[T]{&sync.Pool{New: func() any { return fn() }}}
}

func (p *Pool[T]) Get() *T {
Expand Down

0 comments on commit dcca62f

Please sign in to comment.