-
Notifications
You must be signed in to change notification settings - Fork 0
/
slot.js
43 lines (37 loc) · 842 Bytes
/
slot.js
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
/**
* @class 使用数组实现的延迟任务槽, 根据类型存放任务请求
*
* task_type | task_request
* -----------------------
* 0 | { start, id, type, timeout, delay, params }
* 1 | { start, id, type, timeout, delay, params }
* 2 | { start, id, type, timeout, delay, params }
* ...
*
* @implements Iterator
*/
class Slot {
/**
*
* @param {Array<String>} ENUM_TASK_TYPES 枚举任务类型
*/
constructor(/** */) {
this.slot = []
}
[Symbol.iterator]() {
return this.slot[Symbol.iterator]()
}
markDone(taskType) {
this.slot[taskType] = null
}
markDelay(taskType, taskRequest) {
this.slot[taskType] = taskRequest
}
hasDone(taskType) {
return !this.slot[taskType]
}
get(taskType) {
return this.slot[taskType]
}
}
module.exports = Slot