-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.js
More file actions
68 lines (52 loc) · 1.59 KB
/
Copy pathtasks.js
File metadata and controls
68 lines (52 loc) · 1.59 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
65
66
67
68
const {Scheduler} = require('../dist')
const moment = require('moment')
let scheduler = new Scheduler()
let isFinished = false
scheduler.addTasks([
{
task: async (my) =>
console.log(`task1 uuid:${my.uuid} run!`),
callback: async (my, result)=>
console.log(`task1 uuid:${my.uuid} callback run!`)
},
{
task: async (my) =>
console.log(`task2 uuid:${my.uuid} run!`),
callback: async (my, result)=>
console.log(`task2 uuid:${my.uuid} callback run!`),
delay: 5000
},
{
task: async (my) =>
console.log(`task4 uuid:${my.uuid} run!`),
callback: async (my, result)=> {
console.log(`task4 uuid:${my.uuid} callback run!`)
},
schedule: moment().add(5, 'second').valueOf()
},
{
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}`)
}
},
{
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()
}
], {
delay: 5000,
loop: ()=>{
if(!isFinished){
console.log(`loop's not end?`)
isFinished = true
return true
}
return false
}
})