multi-tasks 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,34 @@ let processTask = (task, helper)=>{
|
|
|
30
30
|
return 'a result which is not a promise';
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
//
|
|
33
|
+
//Step3, run!
|
|
34
|
+
multiTasks({
|
|
35
|
+
initialTasks: alltasks,
|
|
36
|
+
processTask,
|
|
37
|
+
taskRootFolder: `../examples-tmp-data/example0`, //a directory to store progress and results files, you can check the progress here
|
|
38
|
+
taskId: 'my-task',
|
|
39
|
+
numberOfWorkers: 3, //Assign how many workers are working in parallel
|
|
40
|
+
//autoCloseAfterCompletion: true, //if you have dynamically generated new tasks, put this as false
|
|
41
|
+
shouldTerminate:(info)=>{
|
|
42
|
+
//return true if you need to terminate the whole process
|
|
43
|
+
},
|
|
44
|
+
onFinish: (report)=>{
|
|
45
|
+
console.log('finish callback', report);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Have a try:
|
|
52
|
+
|
|
53
|
+
```shell
|
|
54
|
+
node examples/example0/run
|
|
55
|
+
node examples/example1/run
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
More about the task processing function
|
|
59
|
+
```
|
|
60
|
+
//you can return a promise for async processes
|
|
34
61
|
let processTask = (task, helper)=>{
|
|
35
62
|
let {taskCount} = task;
|
|
36
63
|
|
|
@@ -41,7 +68,7 @@ let processTask = (task, helper)=>{
|
|
|
41
68
|
})
|
|
42
69
|
};
|
|
43
70
|
|
|
44
|
-
//
|
|
71
|
+
//dynamically create a new task while processing
|
|
45
72
|
let processTask = (task, helper)=>{
|
|
46
73
|
let {taskCount} = task;
|
|
47
74
|
|
|
@@ -60,7 +87,7 @@ let processTask = (task, helper)=>{
|
|
|
60
87
|
})
|
|
61
88
|
};
|
|
62
89
|
|
|
63
|
-
//
|
|
90
|
+
//this example shows how to generate/handle exceptions
|
|
64
91
|
let processTask = (task, helper)=>{
|
|
65
92
|
let {taskCount} = task;
|
|
66
93
|
|
|
@@ -88,34 +115,11 @@ let processTask = (task, helper)=>{
|
|
|
88
115
|
}, 10)
|
|
89
116
|
})
|
|
90
117
|
}
|
|
91
|
-
|
|
92
|
-
//Step3, run!
|
|
93
|
-
multiTasks({
|
|
94
|
-
initialTasks: alltasks,
|
|
95
|
-
processTask,
|
|
96
|
-
taskRootFolder: `../examples-tmp-data/example0`, //a directory to store progress and results files, you can check the progress here
|
|
97
|
-
taskId: 'my-task',
|
|
98
|
-
numberOfWorkers: 3, //Assign how many workers are working in parallel
|
|
99
|
-
//autoCloseAfterCompletion: true, //if you have dynamically generated new tasks, put this as false
|
|
100
|
-
shouldTerminate:(info)=>{
|
|
101
|
-
//return true if you need to terminate the whole process
|
|
102
|
-
},
|
|
103
|
-
onFinish: (report)=>{
|
|
104
|
-
console.log('finish callback', report);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
Have a try:
|
|
111
|
-
|
|
112
|
-
```shell
|
|
113
|
-
node examples/example0/run
|
|
114
|
-
node examples/example1/run
|
|
115
118
|
```
|
|
116
119
|
|
|
117
120
|
Changelog:
|
|
118
121
|
|
|
122
|
+
- 2.0.5 Update readme examples
|
|
119
123
|
- 2.0.4 Support resume from a failed task
|
|
120
124
|
- 2.0.3 Fix: mkdir bug on windows
|
|
121
125
|
- 2.0.2 new feature: support shouldTerminate
|