multi-tasks 1.2.1 → 1.2.3

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 CHANGED
@@ -12,16 +12,38 @@ How to use:
12
12
  ```javascript
13
13
  //see examples/example0
14
14
  let multiTasks = require('multi-tasks').multiTasks;
15
+ //You need to provide the data of all subtasks, multi-tasks will automatically split them and execute them in a multi-threaded manner
16
+ let alltasks = [];
17
+ for(let i=0;i<100;i++){
18
+ let task_props = {
19
+ index: i,
20
+ name: `task-${i}`,
21
+ description: `This prop is for a subtask`
22
+ };
23
+ alltasks.push(task_props);
24
+ }
25
+
26
+ //You need to provide a process function to handle a certain sub-task and return the result data
27
+ let processTask = (task)=>{
28
+ console.log('this is the subtask data you created above:', task);
29
+ let {index} = task;
30
+
31
+ //any exceptions will be captured
32
+ if(index===3) throw 'exception';
33
+ if(index===4) return Promise.reject({err:'a test error'});
34
+
35
+ //the returned data will be saved
36
+ return Promise.resolve({
37
+ message: 'this is a result from a demo, random data=' + Math.random()
38
+ });
39
+ }
40
+
15
41
  multiTasks({
16
- tasks: [...], //You need to provide an array containing all the subtasks you want to execute, multi-tasks will automatically split them and execute them in a multi-threaded manner
17
- processTask:(task)=>{//You need to provide a processTask function to process a certain sub-task and return the result data
18
- //process your task
19
- let data = {...};
20
- return Promise.resolve(data);
21
- },
22
- multi_task_parent_folder: `C:/tmp-demo`, //a directory to store progress and results files
23
- quotaOfEachTask:2, //The number of tasks assigned to each worker
24
- numberOfWorks: 6
42
+ tasks: alltasks,
43
+ processTask,
44
+ multi_task_parent_folder: `C:/tmp-demo`, //a directory to store progress and results files, you can check the progress here
45
+ quotaOfEachTask:1, //The number of subtasks assigned to each worker at one time, the default is 1
46
+ numberOfWorks: 6 //Assign how many workers are working in parallel
25
47
  });
26
48
 
27
49
  ```
@@ -49,6 +71,8 @@ node examples/example1/run
49
71
 
50
72
  Changelog:
51
73
 
74
+ - 1.2.3 Update README
75
+ - 1.2.2 Update README and examples
52
76
  - 1.2.1 Handle exceptions and errors in subtasks
53
77
  - 1.2.0 Simplified usage by providing the function way and support return Promise
54
78
  - 1.1.4 Remove make-dir
@@ -1,7 +1,8 @@
1
1
  let multiTasks = require('../../index').multiTasks;
2
2
 
3
- let alltasks = []
4
- for(let i=0;i<12;i++){
3
+ //You need to provide the data of all subtasks, multi-tasks will automatically split them and execute them in a multi-threaded manner
4
+ let alltasks = [];
5
+ for(let i=0;i<100;i++){
5
6
  let task_props = {
6
7
  index: i,
7
8
  name: `task-${i}`,
@@ -10,20 +11,25 @@ for(let i=0;i<12;i++){
10
11
  alltasks.push(task_props);
11
12
  }
12
13
 
13
- let processTask = (actionData)=>{
14
- console.log('this is the actionData of one task', actionData);
15
- let {index} = actionData;
14
+ //You need to provide a process function to handle a certain sub-task and return the result data
15
+ let processTask = (task)=>{
16
+ console.log('this is the subtask data you created above:', task);
17
+ let {index} = task;
18
+
19
+ //any exceptions will be captured
16
20
  if(index===3) throw 'exception';
17
21
  if(index===4) return Promise.reject({err:'a test error'});
22
+
23
+ //the returned data will be saved
18
24
  return Promise.resolve({
19
25
  message: 'this is a result from a demo, random data=' + Math.random()
20
26
  });
21
27
  }
22
28
 
23
29
  multiTasks({
24
- tasks: alltasks, //You need to provide the data of all subtasks, multi-tasks will automatically split them and execute them in a multi-threaded manner
25
- processTask, //You need to provide a processTask function to process a certain sub-task and return the result data
26
- multi_task_parent_folder: `C:/tmp-demo`, //a directory to store progress and results files
27
- quotaOfEachTask:2, //The number of tasks assigned to each worker
28
- numberOfWorks: 6
30
+ tasks: alltasks,
31
+ processTask,
32
+ multi_task_parent_folder: `C:/tmp-demo`, //a directory to store progress and results files, you can check the progress here
33
+ quotaOfEachTask:1, //The number of subtasks assigned to each worker at one time, the default is 1
34
+ numberOfWorks: 6 //Assign how many workers are working in parallel
29
35
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multi-tasks",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "directories": {