Repository navigation
Expand file tree
/
Copy pathschedule.js
More file actions
65 lines (49 loc) · 1.68 KB
/
Copy pathschedule.js
File metadata and controls
65 lines (49 loc) · 1.68 KB
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
63
64
const {Scheduler} = require('../dist/')
const moment = require('moment')
let scheduler = new Scheduler()
scheduler.addTask({
task: async (my) =>
console.log(`task1 uuid:${my.uuid} run!`),
callback: async (my, result)=>
console.log(`task1 uuid:${my.uuid} callback run!`)
})
scheduler.addTask({
task: async (my) =>
console.log(`task2 uuid:${my.uuid} run!`),
callback: async (my, result)=>
console.log(`task2 uuid:${my.uuid} callback run!`),
delay: 5000
})
let task5ActingTime = moment().add(10, 'second').valueOf()
scheduler.addTask({
task: async (my) =>
console.log(`task4 uuid:${my.uuid} run!`),
callback: async (my, result)=> {
console.log(`task4 uuid:${my.uuid} callback run!`)
scheduler.addTask({
task: async (my) =>
console.log(`task5 uuid:${my.uuid} run!`),
callback: async (my, result)=>
console.log(`task5 uuid:${my.uuid} callback run!`),
// schedule: moment().add(5, 'second').valueOf(),
loop: ({clear})=>{
if(Date.now() >= task5ActingTime){
clear()
return true
}
return false
}
})
},
schedule: moment().add(5, 'second').valueOf()
})
let taskHandler =
scheduler.addTask({
task: async (my) =>
console.log(`task3 uuid:${my.uuid} run!`),
callback: async (my, result)=> {
console.log(`task3 uuid:${my.uuid} callback run!`)
console.log(`task3 uuid:${my.uuid} callback isStopped: ${my.isStopped}`)
}
})
taskHandler.isStopped = true