mirror of
https://github.com/duanhf2012/origin.git
synced 2026-03-05 05:27:33 +08:00
新增异步函数执行功能
This commit is contained in:
24
event/eventpool.go
Normal file
24
event/eventpool.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package event
|
||||
|
||||
import "github.com/duanhf2012/origin/util/sync"
|
||||
|
||||
// eventPool的内存池,缓存Event
|
||||
const defaultMaxEventChannelNum = 2000000
|
||||
|
||||
var eventPool = sync.NewPoolEx(make(chan sync.IPoolData, defaultMaxEventChannelNum), func() sync.IPoolData {
|
||||
return &Event{}
|
||||
})
|
||||
|
||||
func NewEvent() *Event{
|
||||
return eventPool.Get().(*Event)
|
||||
}
|
||||
|
||||
func DeleteEvent(event IEvent){
|
||||
eventPool.Put(event.(sync.IPoolData))
|
||||
}
|
||||
|
||||
func SetEventPoolSize(eventPoolSize int){
|
||||
eventPool = sync.NewPoolEx(make(chan sync.IPoolData, eventPoolSize), func() sync.IPoolData {
|
||||
return &Event{}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user