Documentation
¶
Overview ¶
Package sync provides experimental sync-related utilities
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
func Append[V interface{}](slice []V, data ...V) []V
Append is an experiment in appending to slices without using the standard Go append function
func AppendScaled ¶
func AppendScaled[V interface{}](scale float64, slice []V, data ...V) []V
AppendScaled is like Append but includes the scale argument for specifying the cap growth multiplier. The scale value is capped at a minimum of 1.5 and for reference, the Append function uses a hard-coded scale of 2
Types ¶
type Pool ¶
type Pool[V interface{}] interface { // Scale returns the amount of instances to Seed this sync.Pool when drained Scale() int // Ready returns the best-guess number of instances still in the sync.Pool Ready() int // Seed adds a count of new instances to this sync.Pool Seed(count int) // Get retrieves a typed instance from this sync.Pool, and if the pool is // drained, uses Seed with Scale to expand this sync.Pool Get() V // Put recycles an existing instance, ignores nil instances Put(v V) }
Pool is a convenience interface for working with the standard sync.Pool.
Pool instances can have up to two hooks provided, the first is always the "getter" PoolHookFn and the second is always the "setter" PoolHookFn.
The "getter" function is used to modify the instance before returning it during Get calls
The "setter" function is used to modify the instance before putting it into the sync.Pool
func NewPool ¶
func NewPool[V interface{}](scale int, maker func() V, hooks ...PoolHookFn[V]) Pool[V]
NewPool constructs a new Pool instance with the given scale, maker function and the two optional PoolHookFn functions
Passing nil for the hooks is valid, for example to create a Pool without a getter hook but with a setter, pass a nil for the first hooks argument
Scale values less than or equal to zero are clamped to a minimum scale of 1
func NewStringBuilderPool ¶
NewStringBuilderPool is a convenience wrapper around NewPool, configured for the *strings.Builder type (all Pool values must be pointers), and includes both getter and setter PoolHookFn implementations. The getter function resets the buffer before returning it and the setter function won't allow recycling buffers that are larger than 65k
type PoolHookFn ¶
type PoolHookFn[V interface{}] func(v V) V
PoolHookFn is the function signature used with NewPool