Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetObjectsInUse ¶
func GetObjectsInUse() uint64
GetObjectsInUse returns total amount of objects taken from all pools but not returned useful in tests
func PrintNonReleased ¶
PrintNonReleased prints stacktraces that explains where non-released objects were borrowed note: debug mode must be turned on by `pool.SetDebug(true)` call
func RegisterObjectsInUseCounter ¶
func RegisterObjectsInUseCounter(oc func() uint64)
RegisterObjectsInUseCounter registers pooled objects counter which will be considered by GetObjectsInUse() called automatically on each NewPool() to track the new pool useful if e.g. we have different pool somewhere else it is useful to register its counter here and use pool.GetObjectsInUse() only as a single pooled objects counter note: func counter must be thread-safe
Types ¶
type IPool ¶
type IPool[T any] interface { Get() T // borrows an object from pool which can be released by releaser func only. obj.Release() causes panic. // use case: pooled root object owns a nested pooled object. Borrow nested by GetOwned to avoid nested release before root release GetOwned(owner IReleaser) T }
IPool s.e. use NewPool() and NewPoolStub()
func NewPoolStub ¶
NewPoolStub creates pool which does not act as a pool. I.e. just creates a new instance on each Get() Release() does nothing more but Cleaunp() call if it exists does not track borrow source code points in debug mode useful for investigations
type IReleaser ¶
type IReleaser interface {
// Release returns the owner instance to the pool
// panics if released already avoiding returning the same object to the pool twice
// calls owner's Cleanup() if exists before returning to pool
Release()
IsOwned() bool
// contains filtered or unexported methods
}
IReleaser provides ability to return the instance which holds the IReleaser to the pool owner instance must set its internal IReleaser to the implementation obtained from the pool see NewPool() instantiator argument