Documentation ¶
Overview ¶
Package objectpool provides Pool of interface PoolObject
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateObjectFn ¶
type CreateObjectFn func() (PoolObject, error)
CreateObjectFn create new object, it must return a health object or err
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manage the PoolObject
func New ¶
func New(initSize, maxSize int, init func() (PoolObject, error)) *Pool
New returns a new pool
func (*Pool) Get ¶
func (p *Pool) Get(ctx context.Context, new CreateObjectFn) (PoolObject, error)
Get returns an object from the pool,
if there's an available object, it will return it directly; if there's no free object, it will create a one if the pool is not full; if the pool is full, it will block until an object is returned to the pool.
type PoolObject ¶
type PoolObject interface { Destroy() // destroy the object HealthCheck() bool // check the object is health or not }
PoolObject is an interface that about definition of object that managed by pool
type Spec ¶
type Spec struct { InitSize int // initial size MaxSize int // max size Init CreateObjectFn // create init size object, it must return a health object or err CheckWhenGet bool // whether to health check when get PoolObject CheckWhenPut bool // whether to health check when put PoolObject }
Spec Pool's spec
Click to show internal directories.
Click to hide internal directories.