-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
task_list.go
50 lines (42 loc) · 838 Bytes
/
task_list.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
package xxl
import "sync"
//任务列表 [JobID]执行函数,并行执行时[+LogID]
type taskList struct {
mu sync.RWMutex
data map[string]*Task
}
// Set 设置数据
func (t *taskList) Set(key string, val *Task) {
t.mu.Lock()
t.data[key] = val
t.mu.Unlock()
}
// Get 获取数据
func (t *taskList) Get(key string) *Task {
t.mu.RLock()
defer t.mu.RUnlock()
return t.data[key]
}
// GetAll 获取数据
func (t *taskList) GetAll() map[string]*Task {
t.mu.RLock()
defer t.mu.RUnlock()
return t.data
}
// Del 设置数据
func (t *taskList) Del(key string) {
t.mu.Lock()
delete(t.data, key)
t.mu.Unlock()
}
// Len 长度
func (t *taskList) Len() int {
return len(t.data)
}
// Exists Key是否存在
func (t *taskList) Exists(key string) bool {
t.mu.RLock()
defer t.mu.RUnlock()
_, ok := t.data[key]
return ok
}