gpool

package
v1.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2019 License: MIT Imports: 6 Imported by: 0

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 ExpireFunc

type ExpireFunc func(interface{})

Destruction function for object.

type NewFunc

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

Creation function for object.

type Pool

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

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

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.

func (*Pool) Get

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

Get picks an item from pool.

func (*Pool) Put

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

Put puts an item to pool.

func (*Pool) Size

func (p *Pool) Size() int

Size returns the count of available items of pool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL