gf: Index | Files

package gpool

import ""

Package gpool provides object-reusable concurrent-safe pool.


Package Files


type ExpireFunc Uses

type ExpireFunc func(interface{})

Destruction function for object.

type NewFunc Uses

type NewFunc func() (interface{}, error)

Creation function for object.

type Pool Uses

type Pool struct {
    Expire     int64                       // Max idle time(ms), after which it is recycled.
    NewFunc    func() (interface{}, error) // Callback function to create item.
    ExpireFunc func(interface{})           // Expired destruction function for objects.
    // contains filtered or unexported fields

Object-Reusable Pool.

func New Uses

func New(expire int, newFunc NewFunc, expireFunc ...ExpireFunc) *Pool

New returns a new object pool. To ensure execution efficiency, the expiration time cannot be modified once it is set.

Expiration logistics: expire = 0 : not expired; expire < 0 : immediate expired after use; expire > 0 : timeout expired; Note that the expiration time unit is ** milliseconds **.

func (*Pool) Clear Uses

func (p *Pool) Clear()

Clear clears pool, which means it will remove all items from pool.

func (*Pool) Close Uses

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.

func (*Pool) Get Uses

func (p *Pool) Get() (interface{}, error)

Get picks an item from pool.

func (*Pool) Put Uses

func (p *Pool) Put(value interface{})

Put puts an item to pool.

func (*Pool) Size Uses

func (p *Pool) Size() int

Size returns the count of available items of pool.

Package gpool imports 6 packages (graph) and is imported by 4 packages. Updated 2019-07-14. Refresh now. Tools for package owners.