Documentation
¶
Overview ¶
Package orbyte is a lightweight & safe (buffer-writer | general object) pool.
Index ¶
- type Item
- type Pool
- func (pool *Pool[T]) CountItems() (outside, inside int32)
- func (pool *Pool[T]) Involve(config, obj any) *Item[T]
- func (pool *Pool[T]) LimitInput(n int32)
- func (pool *Pool[T]) LimitOutput(n int32)
- func (pool *Pool[T]) New(config any) *Item[T]
- func (pool *Pool[T]) Parse(config, obj any) *Item[T]
- func (pool *Pool[T]) SetNoPutBack(on bool)
- func (pool *Pool[T]) SetSyncItem(on bool)
- type Pooler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item[T any] struct { // contains filtered or unexported fields }
Item represents a thread-safe user-defined value.
Only the item that has ownership can be a pointer. Do not copy neither Item nor *Item by yourself. You must always use the given methods.
func (*Item[T]) HasInvolved ¶
HasInvolved whether this item is buffered and will be Reset on putting back.
func (*Item[T]) ManualDestroy ¶
func (b *Item[T]) ManualDestroy()
ManualDestroy item and put it back to pool.
Calling this method only when you're sure that no one will use it, or it will cause a panic.
func (*Item[T]) Trans ¶
func (b *Item[T]) Trans() T
Trans disable inner val being reset by destroy and return a safe copy of val.
This method is not thread-safe. Only call once on one item. The item will be destroyed after calling Trans().
Use it to drop your ownership before passing val (not its pointer) to another function that is not controlled by you.
type Pool ¶
type Pool[T any] struct { // contains filtered or unexported fields }
Pool lightweight general pool.
func (*Pool[T]) CountItems ¶
CountItems returns total item count outside and inside.
func (*Pool[T]) Involve ¶
InvolveItem[T any] involve external object into pool.
After that, you must only use the object through Item.
func (*Pool[T]) LimitInput ¶
LimitInputwill automatically set new item no-autodestroy if countout > inlim.
func (*Pool[T]) LimitOutput ¶
LimitOutput will automatically set new item no-autodestroy if countout > outlim.
func (*Pool[T]) Parse ¶
ParseItem[T any] safely convert obj into pool item without copy.
You can still use the original object elsewhere.
func (*Pool[T]) SetNoPutBack ¶
SetNoPutBack make it panic on every use-after-destroy.
Enable this to detect coding errors.
func (*Pool[T]) SetSyncItem ¶
SetSyncItem make it panic on every read-write conflict.
Enable this to detect coding errors.