pool

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PoolWrapper

func PoolWrapper[T, In, Out any](generator Generator[T], fn func(T, In) Out) func(In) Out

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

func PoolWrapperErr[T, In any](generator Generator[T], fn func(T, In) error) func(In) error

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

type Generator

type Generator[T any] func() T

Generator is a constructor function of some resource

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL