dpool

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpireFunc

type ExpireFunc func(interface{})

type NewFunc

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

type Pool

type Pool struct {
	TTL        time.Duration
	NewFunc    func() (interface{}, error)
	ExpireFunc func(interface{})
	// contains filtered or unexported fields
}

Pool 并发安全的对象复用池

func New

func New(ttl time.Duration, newFunc NewFunc, expireFunc ...ExpireFunc) *Pool

New 创建对象池 注意: ttl = 0: 表示不过期。 ttl < 0: 使用后立即过期 ttl > 0: 设置的过期时间

func (*Pool) Clear

func (that *Pool) Clear()

Clear 清除对象池

func (*Pool) Close

func (that *Pool) Close()

Close 关闭该对象池

func (*Pool) Get

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

Get 从对象池中获取对象,如果池中不存在对象,则调用对象生成方法生成对象

func (*Pool) Put

func (that *Pool) Put(value interface{}) error

Put 把对象放回对象池

func (*Pool) Size

func (that *Pool) Size() int

Size 对象池中的对象数目

type SyncPool

type SyncPool struct {
	// contains filtered or unexported fields
}

func NewSyncPool

func NewSyncPool(newFunc func() interface{}, init func(interface{})) *SyncPool

NewSyncPool 创建对象池 newFunc:创建对象的方法 init: 对象被创建后,返回之前,调用该方法初始化对象

func (*SyncPool) Get

func (that *SyncPool) Get() interface{}

Get 获取对象

func (*SyncPool) Put

func (that *SyncPool) Put(value interface{})

Put 把对象放回对象池

Jump to

Keyboard shortcuts

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