Documentation
¶
Index ¶
- Variables
- type GoroutinePool
- func (pool *GoroutinePool) AvailableInQueue() int
- func (pool *GoroutinePool) IsStopped() bool
- func (pool *GoroutinePool) MaxWorkerNum() int
- func (pool *GoroutinePool) QueueCapacity() int
- func (pool *GoroutinePool) Start() error
- func (pool *GoroutinePool) Stop(ctx context.Context) error
- func (pool *GoroutinePool) Submit(task func()) error
- func (pool *GoroutinePool) WaitingTask() int
- func (pool *GoroutinePool) WorkerNum() int
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidMaxWorkerNum = errors.New("invalid max worker num") ErrInvalidTaskQueueSize = errors.New("invalid task queue size") ErrStartGoroutinePoolFirst = errors.New("please start GoroutinePool first") ErrGoroutinePoolClosed = errors.New("GoroutinePool has been closed") ErrFullTaskQueue = errors.New("task queue is full") )
Functions ¶
This section is empty.
Types ¶
type GoroutinePool ¶
type GoroutinePool struct {
// contains filtered or unexported fields
}
GoroutinePool
@Description: 协程池 为了使运行协程数与并发提交数可控而设计的协程池 该协程池能安全关闭,在停止时优先尝试处理完队列中的任务
func NewGoroutinePool ¶
func NewGoroutinePool(name string, maxWorkerNum int, taskQueueSize int, blockingOrNot bool) (*GoroutinePool, error)
NewGoroutinePool
@Description: 构建协程池 协程池最大同时可承受任务数为 maxWorkerNum + taskQueueSize @param name string 命名 @param maxWorkerNum int 最大支持同时运行协程数(小于等于0时无限制) @param taskQueueSize int 最大任务队列数,也是最大可并发提交任务数(非负数) @param blockingOrNot bool 队列已满时是否进行阻塞,或直接返回错误 @return error
func (*GoroutinePool) AvailableInQueue ¶
func (pool *GoroutinePool) AvailableInQueue() int
AvailableInQueue
@Description: 队列中可用空间数 @receiver pool *GoroutinePool @return int
func (*GoroutinePool) IsStopped ¶
func (pool *GoroutinePool) IsStopped() bool
IsStopped
@Description: 判定池是否以关闭 @receiver pool *GoroutinePool @return bool
func (*GoroutinePool) MaxWorkerNum ¶
func (pool *GoroutinePool) MaxWorkerNum() int
MaxWorkerNum
@Description: 最大工作协程数 @receiver pool *GoroutinePool
func (*GoroutinePool) QueueCapacity ¶
func (pool *GoroutinePool) QueueCapacity() int
QueueCapacity
@Description: 队列容量 @receiver pool *GoroutinePool @return int
func (*GoroutinePool) Start ¶
func (pool *GoroutinePool) Start() error
func (*GoroutinePool) Submit ¶
func (pool *GoroutinePool) Submit(task func()) error
Submit
@Description: 提交任务到协程池 当任务队列中积压的消息(处理不过来)超过队列长度,该方法将阻塞直到队列有空位 @receiver pool *GoroutinePool @param task func() @return error 如果池子已经关闭,则会返回 ErrGoroutinePoolClosed
func (*GoroutinePool) WaitingTask ¶
func (pool *GoroutinePool) WaitingTask() int
WaitingTask
@Description: 队列中等待的任务数 @receiver pool *GoroutinePool @return int
func (*GoroutinePool) WorkerNum ¶
func (pool *GoroutinePool) WorkerNum() int
WorkerNum
@Description: 运行的工作协程数量(而非工作中协程数量) @receiver pool *GoroutinePool
Click to show internal directories.
Click to hide internal directories.