Generic sync.Pool in Go
- Go 100%
| genpool.go | ||
| go.mod | ||
| License.txt | ||
| Readme.md | ||
genpool
Simple generic wrapper around sync.Pool.
Basic pool
var gPool = genpool.New[bytes.Buffer]()
Pool with function
var gPool = genpool.NewFunc[Ctx](func() *Ctx {
return &Ctx{
// ...
}
})
Using the pool
func something() {
buffer := gPool.Get()
defer gPool.Put(buffer)
// do something with buffer
}
The Resetter interface
If the type you're using implements genpool.Resetter (the Reset() method),
it will automatically be called when calling Put().
License
This is free and unencumbered software released into the public domain.