mirror of
https://github.com/panjf2000/ants.git
synced 2025-12-16 09:51:02 +00:00
* add loop queue
* add loop queue
* fix the bugs
add loop queue
move the worker queue to directory
按照新的接口实现 lifo 队列
添加新接口的环形队列实现
rename the slice queue
修复了 unlock
使用 queue 管理 goWorkerWithFunc
使用 dequeue 判断队列
add remainder
增加测试文件
循环队列需要一个空闲位
* remove interface{}
* Refine the logic of sync.Pool
* Add flowcharts of ants into READMEs
* Add the installation about ants v2
* Renew the functional options in READMEs
* Renew English and Chinese flowcharts
* rename package name
移动 worker queue 位置
worker queue 都修改为私有接口
考虑到性能问题,把 interface{} 改回到 *goworker
* 修改 releaseExpiry 和 releaseAll
* remove files
* fix some bug
40 lines
655 B
Go
40 lines
655 B
Go
package ants
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
ErrQueueIsFull = errors.New("the queue is full")
|
|
ErrQueueLengthIsZero = errors.New("the queue length is zero")
|
|
)
|
|
|
|
type workerQueue interface {
|
|
len() int
|
|
cap() int
|
|
isEmpty() bool
|
|
enqueue(worker *goWorker) error
|
|
dequeue() *goWorker
|
|
releaseExpiry(duration time.Duration) chan *goWorker
|
|
releaseAll()
|
|
}
|
|
|
|
type queueType int
|
|
|
|
const (
|
|
stackType queueType = 1 << iota
|
|
loopQueueType
|
|
)
|
|
|
|
func newQueue(qType queueType, size int) workerQueue {
|
|
switch qType {
|
|
case stackType:
|
|
return newWorkerStack(size)
|
|
case loopQueueType:
|
|
return newLoopQueue(size)
|
|
default:
|
|
return newWorkerStack(size)
|
|
}
|
|
}
|