Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ObjectPool ¶
type ObjectPool[T any] struct { // contains filtered or unexported fields }
ObjectPool 基于 sync.Pool 实现的线程安全的对象池
- 一些高频临时生成使用的对象可以通过 ObjectPool 进行管理,例如属性计算等
func NewObjectPool ¶
func NewObjectPool[T any](generator func() *T, releaser func(data *T)) *ObjectPool[*T]
NewObjectPool 创建一个 ObjectPool
Example ¶
package main import ( "fmt" "github.com/kercylan98/minotaur/toolkit/collection" "github.com/kercylan98/minotaur/toolkit/pools" ) func main() { var p = pools.NewObjectPool[map[int]int](func() *map[int]int { return &map[int]int{} }, func(data *map[int]int) { collection.ClearMap(*data) }) m := *p.Get() m[1] = 1 p.Put(&m) fmt.Println(m) }
Output: map[]
type SchedulerPool ¶
type SchedulerPool struct {
// contains filtered or unexported fields
}
SchedulerPool 是一个线程安全的 chrono.Scheduler 对象池
func NewSchedulerPool ¶
func NewSchedulerPool(capacity int, tick time.Duration, wheelSize int64, hungry ...bool) *SchedulerPool
NewSchedulerPool 创建一个 SchedulerPool 对象
- capacity: 调度器池容量
- tick: 时间轮刻度
- wheelSize: 时间轮大小
- hungry: 是否饥饿模式,饥饿模式下,调度器池默认将创建 capacity 指定数量的调度器
func (*SchedulerPool) Put ¶
func (p *SchedulerPool) Put(scheduler *chrono.Scheduler)
Put 将使用完成的调度器放回缓冲区,如果缓冲区已满,则关闭调度器并释放资源
Click to show internal directories.
Click to hide internal directories.