Documentation
¶
Index ¶
- func PoolWrapper[T, In, Out any](generator Generator[T], fn func(T, In) Out) func(In) Out
- func PoolWrapperErr[T, In any](generator Generator[T], fn func(T, In) error) func(In) error
- func PoolWrapperWithErr[T, In, Out any](generator Generator[T], fn func(T, In) (Out, error)) func(In) (Out, error)
- type Generator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PoolWrapper ¶
PoolWrapper is a generic wrapper over some function that requires a resource pool. Under the hood, sync.Pool is used to facilitate pooling.
Usage example:
hashFn := PoolWrapper(sha256.New, func(h hash.Hash, data []byte) [32]byte {
var b [32]byte
_, err := h.Write(data)
defer h.Reset()
if err != nil {
return b
}
h.Sum(b[:0])
return b
})
h := hashFn([]byte("dummy bytes"))
func PoolWrapperErr ¶
PoolWrapperErr is a generic wrapper over some function that requires a resource pool, the function is expected to return error only. Under the hood, sync.Pool is used to facilitate pooling.
func PoolWrapperWithErr ¶
func PoolWrapperWithErr[T, In, Out any](generator Generator[T], fn func(T, In) (Out, error)) func(In) (Out, error)
PoolWrapperWithErr is a generic wrapper over some function that requires a resource pool, and returns error in addition to some output. Under the hood, sync.Pool is used to facilitate pooling.
Types ¶
Click to show internal directories.
Click to hide internal directories.