Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrQueueOverload will be returned on submit operation // when both goroutines pool and priority queue are full. ErrQueueOverload = errors.New("pool and priority queue are full") // ErrPoolCapacitySize will be returned when constructor // provided with non-positive pool capacity. ErrPoolCapacitySize = errors.New("pool capacity must be positive") )
Functions ¶
This section is empty.
Types ¶
type PriorityPool ¶
type PriorityPool struct {
// contains filtered or unexported fields
}
PriorityPool is a pool of goroutines with priority queue buffer. Based on panjf2000/ants and stdlib heap libraries.
func New ¶
func New(poolCapacity, queueCapacity int) (*PriorityPool, error)
New creates instance of priority pool. Pool capacity must be positive. Zero queue capacity disables priority queue. Negative queue capacity disables priority queue length limit.
func (*PriorityPool) Submit ¶
func (p *PriorityPool) Submit(priority uint32, task func()) error
Submit sends the task into priority pool. Non-blocking operation. If pool has available workers, then task executes immediately. If pool is full, then task is stored in priority queue. It will be executed when available worker pops the task from priority queue. Tasks from queue do not evict running tasks from pool. Tasks with bigger priority number are popped earlier. If queue is full, submit returns ErrQueueOverload error.