-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathqueue.go
47 lines (41 loc) · 984 Bytes
/
queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package queue
var (
internalQueue Queuer
)
// Queuer a task queue for mitigating server pressure in high concurrency situations
// and improving task processing
type Queuer interface {
Run()
Push(job Jober)
Terminate()
}
// Run start running queues,
// specify the number of buffers, and the number of worker threads
func Run(maxCapacity, maxThread int) {
if internalQueue == nil {
internalQueue = NewQueue(maxCapacity, maxThread)
}
internalQueue.Run()
}
// RunListQueue start running list queues
// ,specify the number of worker threads
func RunListQueue(maxThread int) {
if internalQueue == nil {
internalQueue = NewListQueue(maxThread)
}
internalQueue.Run()
}
// Push put the executable task into the queue
func Push(job Jober) {
if internalQueue == nil {
return
}
internalQueue.Push(job)
}
// Terminate terminate the queue to receive the task and release the resource
func Terminate() {
if internalQueue == nil {
return
}
internalQueue.Terminate()
}