Documentation ¶
Index ¶
Constants ¶
View Source
const ( // 預設 Pool 最大容量 DefaultPoolSize = math.MaxInt32 // 預設每 1 秒清理一次 Pool DefaultCleanIntervalTime = time.Second )
View Source
const ( // Pool 開啟 OPENED = 0 // Pool 關閉 CLOSED = 1 )
Pool 狀態
Variables ¶
View Source
var ( ErrLackPoolFunc = errors.New("must provide func for pool") ErrInvalidPoolExpiry = errors.New("invalid pool expiry") ErrPoolClosed = errors.New("pool has been closed") ErrPoolOverload = errors.New("too many goroutines blocked or Nonblocking is set") ErrInvalidPreAllocSize = errors.New("can not set up a negative capacity under PreAlloc mode") ErrTimeout = errors.New("operation timed out") )
定義各種錯誤
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(opts *Options)
參數設定
func WithNonblocking ¶
若為 true,代表沒有有用的 Worker 時,會直接 ErrPoolOverload
type Options ¶
type Options struct { // 過期時間: 用於定時清理過期的 Worker (只要太久沒被使用的 Worker 就會被清理),預設為 1 秒 ExpiryDuration time.Duration // 是否提前申請空間,大量執行需求中使用 PreAlloc bool // Nonblocking 用來阻塞任務 // 若設定為 true,就會返回 ErrPoolOverload 錯誤 Nonblocking bool // 用來處理 worker panic 發生的事件 PanicHandler func(interface{}) // 若設定為 true,Worker 就不會被自動清除 DisableClear bool }
該設定會被用來引入至 Pool 中
Click to show internal directories.
Click to hide internal directories.