mirror of https://github.com/panjf2000/ants.git
optimization for default pool
This commit is contained in:
parent
020959a1d5
commit
9af581c867
27
ants.go
27
ants.go
|
@ -36,7 +36,26 @@ const (
|
|||
)
|
||||
|
||||
// Init a instance pool when importing ants
|
||||
var defaultAntsPool, _ = NewPool(DefaultAntsPoolSize)
|
||||
var (
|
||||
defaultAntsPool *Pool
|
||||
err error
|
||||
)
|
||||
|
||||
func init() {
|
||||
defaultAntsPool, err = NewPool(DefaultAntsPoolSize)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Release Closed the default pool
|
||||
func Release() {
|
||||
defaultAntsPool.Release()
|
||||
defaultAntsPool, err = NewPool(DefaultAntsPoolSize)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Submit submit a task to pool
|
||||
func Submit(task f) error {
|
||||
|
@ -58,12 +77,6 @@ func Free() int {
|
|||
return defaultAntsPool.Free()
|
||||
}
|
||||
|
||||
// Release Closed the default pool
|
||||
func Release() {
|
||||
defaultAntsPool.Release()
|
||||
|
||||
}
|
||||
|
||||
// Errors for the Ants API
|
||||
var (
|
||||
ErrInvalidPoolSize = errors.New("invalid size for pool")
|
||||
|
|
Loading…
Reference in New Issue