gpool
2 分钟阅读
原文:
Package gpool provides object-reusable concurrent-safe pool.
软件包 gpool 提供对象可重用的并发安全池。
常量
This section is empty.
变量
This section is empty.
函数
This section is empty.
类型
type ExpireFunc
|
|
ExpireFunc Destruction function for object.
ExpireFunc 对象的销毁函数。
type NewFunc
|
|
NewFunc Creation function for object.
NewFunc 对象的创建函数。
type Pool
|
|
Pool is an Object-Reusable Pool.
Pool 是一个对象可重用的池。
func New
|
|
New creates and returns a new object pool. To ensure execution efficiency, the expiration time cannot be modified once it is set.
New 创建并返回一个新的对象池。为保证执行效率,过期时间一经设置,无法修改。
Note the expiration logic: ttl = 0 : not expired; ttl < 0 : immediate expired after use; ttl > 0 : timeout expired;
注意过期逻辑:ttl = 0 : 未过期;ttl < 0:使用后立即过期; ttl > 0:超时过期;
Example
|
|
(*Pool) Clear
|
|
Clear clears pool, which means it will remove all items from pool.
清除池,这意味着它将从池中删除所有项目。
Example
|
|
(*Pool) Close
|
|
Close closes the pool. If p
has ExpireFunc, then it automatically closes all items using this function before it’s closed. Commonly you do not need to call this function manually.
关闭 关闭池。如果 p
具有 ExpireFunc,则它会在关闭之前使用此函数自动关闭所有项目。通常,不需要手动调用此函数。
Example
|
|
(*Pool) Get
|
|
Get picks and returns an item from pool. If the pool is empty and NewFunc is defined, it creates and returns one from NewFunc.
从池中获取拣选并返回项目。如果池为空且定义了 NewFunc,则会从 NewFunc 创建并返回一个池。
Example
|
|
(*Pool) MustPut
|
|
MustPut puts an item to pool, it panics if any error occurs.
MustPut 将项目放入池中,如果发生任何错误,它会崩溃。
(*Pool) Put
|
|
Put puts an item to pool.
Put 将项目放入池中。
Example
|
|
(*Pool) Size
|
|
Size returns the count of available items of pool.
Size 返回池中可用项的计数。
Example
|
|
|
|