-
Notifications
You must be signed in to change notification settings - Fork 0
/
queues.go
62 lines (54 loc) · 1.17 KB
/
queues.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package tools
import (
"sync"
)
type LQueues struct {
running sync.Map
}
// 多任务按顺序执行
func NewQueues() *LQueues {
q := new(LQueues)
return q
}
func (q *LQueues) init0() {
return
}
func (q *LQueues) AddTask(key string, task LTask) {
var n *LQueue
if v, ok := q.running.Load(key); !ok {
// no data
n = NewQueue(1)
} else {
n = v.(*LQueue)
}
n.AddTask(task)
q.running.Store(key, n)
printInfo("running queue's count is ")
return
}
func (q *LQueues) Get(key string) (v interface{}, ok bool) {
return q.running.Load(key)
}
func (q *LQueues) Close(key string) {
printInfo("LQueues 准备关闭 " + key + " 的队列")
var n *LQueue
if v, ok := q.running.Load(key); !ok {
printInfo("LQueues 关闭 " + key + " 的队列失败,没有找到这个队列,可能已经关闭了")
return
} else {
n = v.(*LQueue)
}
n.Close()
q.running.Delete(key)
printInfo("LQueues 关闭 " + key + " 的队列成功")
}
func (q *LQueues) CloseAll() {
printInfo("LQueues 准备退出,关闭所有的队列")
q.running.Range(func(key, value interface{}) bool {
n := value.(*LQueue)
n.Close()
q.running.Delete(key)
return true
})
printInfo("LQueues 退出完毕")
}