1
0
Fork 0
Generic sync.Pool in Go
Find a file
2026-03-19 22:40:36 +01:00
genpool.go Initial commit 2026-03-19 22:37:36 +01:00
go.mod Initial commit 2026-03-19 22:37:36 +01:00
License.txt Initial commit 2026-03-19 22:37:36 +01:00
Readme.md Updated readme 2026-03-19 22:40:36 +01:00

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.