gpool

package
v0.0.0-...-3631402 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

对象复用池.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	Expire     int64                       // (毫秒)闲置最大时间,超过该时间则被系统回收
	NewFunc    func() (interface{}, error) // 创建对象的方法定义
	ExpireFunc func(interface{})           // 对象的过期销毁方法(当池对象销毁需要执行额外的销毁操作时,需要定义该方法)
	// contains filtered or unexported fields
}

对象池

func New

func New(expire int, newFunc ...func() (interface{}, error)) *Pool

创建一个对象池,为保证执行效率,过期时间一旦设定之后无法修改 expire = 0表示不过期,expire < 0表示使用完立即回收,expire > 0表示超时回收 注意过期时间单位为**毫秒**

func (*Pool) Close

func (p *Pool) Close()

关闭池

func (*Pool) Get

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

从池中获得一个临时对象

func (*Pool) Put

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

放一个临时对象到池中

func (*Pool) SetExpireFunc

func (p *Pool) SetExpireFunc(expireFunc func(interface{}))

设置对象过期销毁时的关闭方法

func (*Pool) Size

func (p *Pool) Size() int

查询当前池中的对象数量

Jump to

Keyboard shortcuts

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