Documentation ¶
Overview ¶
Package gpool provides object-reusable concurrent-safe pool.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool struct { // Time To Live for pool items. TTL time.Duration // Callback function to create pool item. NewFunc func() (interface{}, error) // ExpireFunc is the for expired items destruction. // This function needs to be defined when the pool items // need to perform additional destruction operations. // Eg: net.Conn, os.File, etc. ExpireFunc func(interface{}) // contains filtered or unexported fields }
Pool is an Object-Reusable Pool.
func New ¶
func New(ttl time.Duration, newFunc NewFunc, expireFunc ...ExpireFunc) *Pool
New creates and returns a new object pool. To ensure execution efficiency, the expiration time cannot be modified once it is set.
Note the expiration logic: ttl = 0 : not expired; ttl < 0 : immediate expired after use; ttl > 0 : timeout expired;
func (*Pool) Clear ¶
func (p *Pool) Clear()
Clear clears pool, which means it will remove all items from pool.
func (*Pool) Close ¶
func (p *Pool) Close()
Close closes the pool. If <p> has ExpireFunc, then it automatically closes all items using this function before it's closed. Commonly you do not need call this function manually.
Click to show internal directories.
Click to hide internal directories.