Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CtxGo ¶
CtxGo runs the given func in background, and it passes ctx to panic handler when happens.
func SetPanicHandler ¶
SetPanicHandler sets a func for handling panic cases.
check the comment of (*GoPool).SetPanicHandler for details
Types ¶
type GoPool ¶
type GoPool struct {
// contains filtered or unexported fields
}
GoPool represents a simple worker pool which manages goroutines for background tasks.
func (*GoPool) CtxGo ¶
CtxGo runs the given func in background, and it passes ctx to panic handler when happens.
func (*GoPool) CurrentWorkers ¶
func (*GoPool) SetPanicHandler ¶
SetPanicHandler sets a func for handling panic cases.
Panic handler takes two args, `ctx` and `r`. `ctx` is the one provided when calling CtxGo, and `r` is returned by recover()
By default, GoPool will use log.Printf to record the err and stack.
It's recommended to set your own handler.
type Option ¶
type Option struct { // MaxIdleWorkers is the max idle workers keeping in pool for waiting tasks. // There workers will exit after `WorkerMaxAge` MaxIdleWorkers int // WorkerMaxAge is the max age of a worker in pool. WorkerMaxAge time.Duration // TaskChanBuffer is the size of task queue length. // if it's full, we will fall back to use `go` directly without using pool. // normally, the queue length should be small, // coz we will create new workers to pick tasks if necessary. TaskChanBuffer int }
Option ...
func DefaultOption ¶
func DefaultOption() *Option
DefaultOption returns the default values of Option.