Documentation
¶
Overview ¶
包gpool提供了对象可重用的并发安全池。 md5:d111530cd572ede7
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool struct {
TTL time.Duration // 对象池中项目的生存时间。 md5:d9c944077d869281
NewFunc func() (interface{}, error) // 创建池项的回调函数。 md5:f37bfc92a2188739
// ExpireFunc 是用于过期项目销毁的函数。
// 当池中的项目需要执行额外销毁操作时,需要定义这个函数。
// 例如:net.Conn、os.File 等。
// md5:f09911de2780aeaa
ExpireFunc func(interface{})
// contains filtered or unexported fields
}
Pool是一个对象可重用池。 md5:08c256ba80594199
func X创建 ¶
func X创建(过期时长 time.Duration, 新创建回调函数 NewFunc, 过期销毁回调函数 ...ExpireFunc) *Pool
X创建 创建并返回一个新的对象池。 为了确保执行效率,一旦设置,过期时间将不能修改。
注意过期逻辑: ttl = 0:未过期; ttl < 0:使用后立即过期; ttl > 0:超时过期。 md5:9f724382dd2313e7
func (*Pool) X入栈PANI ¶
func (p *Pool) X入栈PANI(对象 interface{})
X入栈PANI 将一个项目放入池中,如果发生任何错误,它将引发恐慌。 md5:10206f4587a99039
func (*Pool) X关闭 ¶
func (p *Pool) X关闭()
X关闭 关闭池。如果 `p` 有 ExpireFunc,那么在关闭之前,它会自动使用这个函数关闭所有项目。通常情况下,你不需要手动调用这个函数。 md5:368c18d44115f9cc
Click to show internal directories.
Click to hide internal directories.