Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Go ¶
func Go(f RoutineFunc)
Go is an alternative to the go keyword, which is able to recover panic.
gopool.Go(func(arg interface{}){
...
}(nil))
func RegisterPool ¶
RegisterPool registers a new pool to the global map. GetPool can be used to get the registered pool by name. returns error if the same name is registered.
func SetCap ¶
func SetCap(cap int32)
SetCap is not recommended to be called, this func changes the global pool's capacity which will affect other callers.
func SetPanicHandler ¶
SetPanicHandler sets the panic handler for the global pool.
Types ¶
type Config ¶
type Config struct {
// threshold for scale.
// new goroutine is created if len(task chan) > ScaleThreshold.
// defaults to defaultScalaThreshold.
ScaleThreshold int32
}
Config is used to config pool.
type Pool ¶
type Pool interface {
// Name returns the corresponding pool name.
Name() string
// SetCap sets the goroutine capacity of the pool.
SetCap(cap int32)
// Go executes f.
Go(f RoutineFunc) error
// CtxGo executes f and accepts the context.
CtxGo(ctx context.Context, f RoutineFunc) error
// SetPanicHandler sets the panic handler.
SetPanicHandler(f func(context.Context, error))
// Stop the Pool graceful
Stop(ctx context.Context) error
}
type RoutineFunc ¶
Click to show internal directories.
Click to hide internal directories.