micro/util/xpool/pool.go
Vasiliy Tolstov 76090f7569
Some checks failed
Go / test (push) Failing after 6m9s
/ autoupdate (push) Successful in 1m18s
util/xpool: package pool
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-04-14 00:19:08 +03:00

26 lines
305 B
Go

package pool
import "sync"
type Pool[T any] struct {
p *sync.Pool
}
func NewPool[T any](fn func() T) Pool[T] {
return Pool[T]{
p: &sync.Pool{
New: func() interface{} {
return fn()
},
},
}
}
func (p Pool[T]) Get() T {
return p.p.Get().(T)
}
func (p Pool[T]) Put(t T) {
p.p.Put(t)
}