concurrency.js 0.0.3-beta → 0.0.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/.todo ADDED
@@ -0,0 +1,13 @@
1
+ [TODO]
2
+
3
+ [*] Easy Threading functionality
4
+ [*] Easy Process functionality
5
+ [*] Easy Threading Async functionality
6
+ [*] Easy Cluster (Processess) functionality
7
+ [*] Add Cluster numbers to Concurrency Threading
8
+ [*] Add Demos for all functions
9
+ [] Add Tests for all functions
10
+ [] Add thread numbers to Concurrency Threading. Create different function
11
+ [] Add Process numbers to Concurrency Threading. Create different function
12
+ [] Add Thread Async numbers to Concurrency Async Threading. Create different function
13
+
package/README.md CHANGED
@@ -4,6 +4,7 @@ npm module to work with concurrency - worker threads and worker processes easily
4
4
 
5
5
  Find the demos in the [demos folder](./demos)
6
6
 
7
+
7
8
  #### Cluster Methods
8
9
 
9
10
 
@@ -39,6 +40,7 @@ concurrency();
39
40
 
40
41
  ```
41
42
 
43
+
42
44
  #### Process Methods
43
45
 
44
46
 
@@ -63,6 +65,10 @@ _concurrencyProcesses(
63
65
 
64
66
  ```
65
67
 
68
+
69
+ ![Process Execution Functions](./docs/Concurrency.js.Process.jpg)
70
+
71
+
66
72
  #### Threads Methods
67
73
 
68
74
 
@@ -86,6 +92,10 @@ _concurrencyThreads(
86
92
 
87
93
  ```
88
94
 
95
+
96
+ ![Threads Execution Functions](./docs/Concurrency.js.Threads.jpg)
97
+
98
+
89
99
  #### Thread Async Methods
90
100
 
91
101
 
@@ -110,10 +120,21 @@ let threads = _concurrencyThreadsAsync(
110
120
 
111
121
  ```
112
122
 
123
+
124
+
113
125
  ### Contributions
114
126
 
115
127
  Contributions, Feature Improvements, Bugs, and Issues are invited. [raising an issue](https://github.com/ganeshkbhat/concurrency.js/issues)
116
128
 
129
+
130
+
131
+ ### TODO
132
+
133
+ [Todo](./todo)
134
+
135
+
136
+
117
137
  # License
118
138
 
119
139
  [MIT License](./LICENSE)
140
+
@@ -18,5 +18,5 @@ console.log(` STDOUT: console.log(threads.stderr); console.log(threads.stdout);
18
18
  console.log(threads.stderr);
19
19
  console.log(threads.stdout);
20
20
 
21
- // setTimeout(() => console.log(`demo.cluster.js: run file PID ${process.pid}: Interval 2: 10000 `, process.pid), 10000);
22
- // setTimeout(() => console.log(`demo.cluster.js: Closing process ${process.pid}: Timeout 1: 10000 `, process.exit()), 20000);
21
+ setTimeout(() => console.log(`demo.threads.async.js: run file PID ${process.pid}: Interval 2: 10000 `, process.pid), 10000);
22
+ setTimeout(() => console.log(`demo.threads.async.js: Closing process ${process.pid}: Timeout 1: 10000 `, process.exit()), 20000);
@@ -35,6 +35,6 @@ _concurrencyThreads(__filename, {
35
35
  // process.exit(0);
36
36
  // }, 20000);
37
37
 
38
- setTimeout(() => console.log(`demo.processes.js: Run file PID ${process.pid}: Interval 2: 10000 `, process.pid), 10000);
39
- setTimeout(() => console.log(`demo.processes.js: Closing process ${process.pid}: Timeout 1: 10000 `, process.exit()), 20000);
38
+ setTimeout(() => console.log(`demo.threads.js: Run file PID ${process.pid}: Interval 2: 10000 `, process.pid), 10000);
39
+ setTimeout(() => console.log(`demo.threads.js: Closing process ${process.pid}: Timeout 1: 10000 `, process.exit()), 20000);
40
40
 
Binary file
Binary file
Binary file
Binary file
package/index.js CHANGED
@@ -27,9 +27,20 @@ module.exports._concurrencyProcesses = _concurrencyProcesses;
27
27
  module.exports._concurrencyClusters = _concurrencyClusters;
28
28
  module.exports._concurrencyThreadsAsync = _concurrencyThreadsAsync;
29
29
 
30
+ module.exports.concurrencyThreads = _concurrencyThreads;
31
+ module.exports.concurrencyProcesses = _concurrencyProcesses;
32
+ module.exports.concurrencyClusters = _concurrencyClusters;
33
+ module.exports.concurrencyThreadsAsync = _concurrencyThreadsAsync;
34
+
30
35
  module.exports.default = {
31
36
  _concurrencyThreads,
32
37
  _concurrencyProcesses,
33
38
  _concurrencyClusters,
34
- _concurrencyThreadsAsync
39
+ _concurrencyThreadsAsync,
40
+
41
+ concurrencyThreads: _concurrencyThreads,
42
+ concurrencyProcesses: _concurrencyProcesses,
43
+ concurrencyClusters: _concurrencyClusters,
44
+ concurrencyThreadsAsync: _concurrencyThreadsAsync
45
+
35
46
  };
package/index.mjs CHANGED
@@ -15,7 +15,25 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- import { _concurrencyThreads, _concurrencyProcesses, _concurrencyThreadsAsync, _concurrencyThreadsAsync } from "./index.js";
18
+ import {
19
+ _concurrencyThreads,
20
+ _concurrencyProcesses,
21
+ _concurrencyThreadsAsync,
22
+ _concurrencyClusters,
23
+ concurrencyThreads,
24
+ concurrencyProcesses,
25
+ concurrencyClusters,
26
+ concurrencyThreadsAsync
27
+ } from "./index.js";
19
28
 
20
- export { _concurrencyThreads, _concurrencyProcesses, _concurrencyClusters, _concurrencyThreadsAsync };
29
+ export {
30
+ _concurrencyThreads,
31
+ _concurrencyProcesses,
32
+ _concurrencyClusters,
33
+ _concurrencyThreadsAsync,
34
+ concurrencyThreads,
35
+ concurrencyProcesses,
36
+ concurrencyClusters,
37
+ concurrencyThreadsAsync
38
+ };
21
39
  export default _concurrencyProcesses;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "concurrency.js",
3
- "version": "0.0.3-beta",
3
+ "version": "0.0.3",
4
4
  "description": "npm module to work with concurrency - worker threads and worker processes (currrently only fork method) easily using simple functions and script files",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "devDependencies": {
14
14
  "chai": "^4.3.6",
15
- "mocha": "^10.0.0",
15
+ "mocha": "^10.2.0",
16
16
  "npm-check": "^6.0.1",
17
17
  "sinon": "^14.0.0",
18
18
  "unimported": "^1.22.0"
@@ -26,8 +26,13 @@
26
26
  },
27
27
  "homepage": "https://github.com/ganeshkbhat/concurrency#readme",
28
28
  "scripts": {
29
- "test": "mocha --reporter spec --recursive --timeout 60000"
29
+ "test": "mocha --reporter spec --recursive --timeout 60000 && exit"
30
30
  },
31
+ "keys": [
32
+ "concurrency",
33
+ "threads",
34
+ "processes"
35
+ ],
31
36
  "author": "Ganesh B",
32
37
  "license": "MIT"
33
38
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ *
3
+ * Package: concurrency.js
4
+ * Author: Ganesh B
5
+ * Description: npm module to work with concurrency - worker threads and worker processes easily using simple functions and script files
6
+ * Install: npm i concurrency.js --save
7
+ * Github: https://github.com/ganeshkbhat/concurrency
8
+ * npmjs Link: https://www.npmjs.com/package/
9
+ * File: worker.cluster.threads.js
10
+ * File Description:
11
+ *
12
+ */
13
+
14
+ /* eslint no-console: 0 */
15
+
16
+ 'use strict';
17
+
18
+ const path = require("path");
19
+ const fs = require("fs");
20
+
@@ -18,8 +18,6 @@
18
18
  const path = require('path');
19
19
  const fs = require('fs');
20
20
 
21
-
22
-
23
21
  function _concurrencyThreads(filename = __filename, options = {}, greet = false) {
24
22
  const { Worker, isMainThread, parentPort } = require('worker_threads');
25
23
 
@@ -73,7 +71,7 @@ function _concurrencyThreads(filename = __filename, options = {}, greet = false)
73
71
  const cbFunction = require(options.handlers.error);
74
72
  result.push({ message: cbFunction(e), pid: process.pid, event: "error" });
75
73
  }
76
- reject(e)
74
+ reject({ e, result });
77
75
  });
78
76
 
79
77
  worker.on("messageerror", (e) => {
@@ -81,7 +79,7 @@ function _concurrencyThreads(filename = __filename, options = {}, greet = false)
81
79
  const cbFunction = require(options.handlers.messageerror);
82
80
  result.push({ message: cbFunction(e), pid: process.pid, event: "messageerror" });
83
81
  }
84
- reject(e)
82
+ reject({ e, result });
85
83
  });
86
84
 
87
85
  worker.on("close", (e) => {
@@ -91,7 +89,7 @@ function _concurrencyThreads(filename = __filename, options = {}, greet = false)
91
89
  const cbFunction = require(options.handlers.close);
92
90
  result.push({ message: cbFunction(e), pid: process.pid, event: "close" });
93
91
  }
94
- // resolve({ messageData, result });
92
+ reject({ e, result });
95
93
  });
96
94
 
97
95
  worker.on("exit", (code) => {
@@ -105,6 +103,7 @@ function _concurrencyThreads(filename = __filename, options = {}, greet = false)
105
103
  }
106
104
  // reject(new Error(`Worker (PID ${process.pid}) threadID:${worker.threadId} stopped with exit code ${code}`));
107
105
  });
106
+
108
107
  worker.postMessage({ closeChild: true });
109
108
  // });
110
109
 
@@ -0,0 +1,46 @@
1
+ // /**
2
+ // *
3
+ // * Package: concurrency.js
4
+ // * Author: Ganesh B
5
+ // * Description: npm module to work with concurrency - worker threads and worker processes easily using simple functions and script files
6
+ // * Install: npm i --save
7
+ // * Github: https://github.com/ganeshkbhat/concurrency
8
+ // * npmjs Link: https://www.npmjs.com/package/concurrency.js
9
+ // * File: test.demos.cluster.js
10
+ // * File Description:
11
+ // *
12
+ // */
13
+
14
+ // /* eslint no-console: 0 */
15
+
16
+
17
+ // 'use strict';
18
+
19
+ // const path = require("path");
20
+ // let { _concurrencyClusters } = require("../index.js");
21
+
22
+ // async function concurrency() {
23
+ // var responses;
24
+ // async function testPromise() {
25
+ // try {
26
+ // let filename = "C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.cluster.js";
27
+ // responses = await _concurrencyClusters(
28
+ // path.join(filename),
29
+ // 8,
30
+ // {
31
+ // data: {
32
+ // message: "Testing parent data",
33
+ // url: "https://www.google.com",
34
+ // },
35
+ // childData: "Test data from child"
36
+ // }
37
+ // );
38
+ // return responses;
39
+ // } catch (e) {
40
+ // return e;
41
+ // }
42
+ // };
43
+ // return await testPromise();
44
+ // }
45
+
46
+ // module.exports.concurrency = concurrency();
@@ -0,0 +1,42 @@
1
+ /**
2
+ *
3
+ * Package: concurrency.js
4
+ * Author: Ganesh B
5
+ * Description: npm module to work with concurrency - worker threads and worker processes easily using simple functions and script files
6
+ * Install: npm i --save
7
+ * Github: https://github.com/ganeshkbhat/concurrency
8
+ * npmjs Link: https://www.npmjs.com/package/concurrency.js
9
+ * File: test.demos.cluster.js
10
+ * File Description:
11
+ *
12
+ */
13
+
14
+ /* eslint no-console: 0 */
15
+
16
+
17
+ 'use strict';
18
+
19
+ const path = require("path");
20
+ let { _concurrencyProcesses } = require("../index.js");
21
+
22
+ async function concurrency() {
23
+ var responses;
24
+ async function testPromise() {
25
+ try {
26
+ let filename = "C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.process.js";
27
+ responses = await _concurrencyProcesses(
28
+ path.join(filename), {
29
+ data: {
30
+ message: "Testing data",
31
+ url: "https://www.google.com"
32
+ }
33
+ }, true);
34
+ return responses;
35
+ } catch (e) {
36
+ return e;
37
+ }
38
+ };
39
+ return await testPromise();
40
+ }
41
+
42
+ module.exports.concurrency = concurrency();
@@ -0,0 +1,43 @@
1
+ /**
2
+ *
3
+ * Package: concurrency.js
4
+ * Author: Ganesh B
5
+ * Description: npm module to work with concurrency - worker threads and worker processes easily using simple functions and script files
6
+ * Install: npm i --save
7
+ * Github: https://github.com/ganeshkbhat/concurrency
8
+ * npmjs Link: https://www.npmjs.com/package/concurrency.js
9
+ * File: test.demos.cluster.js
10
+ * File Description:
11
+ *
12
+ */
13
+
14
+ /* eslint no-console: 0 */
15
+
16
+
17
+ 'use strict';
18
+
19
+ const path = require("path");
20
+ let { _concurrencyThreads } = require("../index.js");
21
+
22
+ // _concurrencyThreads(path.join("C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.threads.js"), { data: { url: "https://www.google.com", message: "Testing data" } });
23
+
24
+ async function concurrency() {
25
+ var responses;
26
+ async function testPromise() {
27
+ try {
28
+ responses = await _concurrencyThreads(__filename, {
29
+ data: {
30
+ message: "Testing data",
31
+ url: "https://www.google.com"
32
+ },
33
+ childData: "Testing child data"
34
+ });
35
+ return responses;
36
+ } catch (e) {
37
+ return e;
38
+ }
39
+ };
40
+ return await testPromise();
41
+ }
42
+
43
+ module.exports.concurrency = concurrency();
@@ -23,87 +23,56 @@
23
23
 
24
24
  // describe('test-.js::concurrency.js: [Test A] Test Suite for concurrency.js cluster in main repo directory', function () {
25
25
 
26
- // it('[Test A] Test for cluster function demos', async function (done) {
27
-
28
- // async function res() {
29
- // var responses;
30
- // async function concurrency() {
31
- // let filename = "C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.cluster.js";
32
- // return new Promise(function (resolve, reject) {
33
- // _concurrencyClusters(
34
- // path.join(filename), 8,
35
- // {
36
- // data: {
37
- // message: "Testing parent data",
38
- // url: "https://www.google.com",
39
- // },
40
- // childData: "Test data from child"
41
- // }
42
- // ).then((d) => {
43
- // console.log("Data fetched", JSON.stringify(d));
44
- // resolve(d);
45
- // }).catch((e) => {
46
- // console.log(e.toString());
47
- // reject(e);
48
- // });
49
- // });
50
- // }
51
-
52
- // responses = await concurrency();
53
- // return responses;
54
- // }
55
-
56
- // let response = res();
57
- // // .catch((e) => {
58
- // // console.log(e.toString());
59
- // // expect(!!e.toString()).to.equal(true);
60
- // // done();
61
- // // });
62
-
63
- // // "1":[{"closeChild":true,"pid":7468,"childMessageData":[{"id":"1","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
64
- // expect(JSON.stringify(response.message["1"][0]["closeChild"])).to.equal(true);
65
- // expect(JSON.stringify(response.message["1"][0]["childMessageData"][0]["id"])).to.equal(1);
66
- // expect(JSON.stringify(response.message["1"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
67
-
68
- // // "2":[{"closeChild":true,"pid":13784,"childMessageData":[{"id":"2","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
69
- // expect(JSON.stringify(response.message["2"][0]["closeChild"])).to.equal(true);
70
- // expect(JSON.stringify(response.message["2"][0]["childMessageData"][0]["id"])).to.equal(1);
71
- // expect(JSON.stringify(response.message["2"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
72
-
73
- // // "3":[{"closeChild":true,"pid":872,"childMessageData":[{"id":"3","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
74
- // expect(JSON.stringify(response.message["3"][0]["closeChild"])).to.equal(true);
75
- // expect(JSON.stringify(response.message["3"][0]["childMessageData"][0]["id"])).to.equal(1);
76
- // expect(JSON.stringify(response.message["3"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
77
-
78
- // // "4": [{"closeChild":true,"pid":11732,"childMessageData":[{"id":"4","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
79
- // expect(JSON.stringify(response.message["4"][0]["closeChild"])).to.equal(true);
80
- // expect(JSON.stringify(response.message["4"][0]["childMessageData"][0]["id"])).to.equal(1);
81
- // expect(JSON.stringify(response.message["4"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
82
-
83
- // // "5":[{"closeChild":true,"pid":7468,"childMessageData":[{"id":"5","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
84
- // expect(JSON.stringify(response.message["5"][0]["closeChild"])).to.equal(true);
85
- // expect(JSON.stringify(response.message["5"][0]["childMessageData"][0]["id"])).to.equal(1);
86
- // expect(JSON.stringify(response.message["5"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
87
-
88
- // // "6":[{"closeChild":true,"pid":13784,"childMessageData":[{"id":"6","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
89
- // expect(JSON.stringify(response.message["6"][0]["closeChild"])).to.equal(true);
90
- // expect(JSON.stringify(response.message["6"][0]["childMessageData"][0]["id"])).to.equal(1);
91
- // expect(JSON.stringify(response.message["6"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
92
-
93
- // // "7":[{"closeChild":true,"pid":872,"childMessageData":[{"id":"7","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
94
- // expect(JSON.stringify(response.message["7"][0]["closeChild"])).to.equal(true);
95
- // expect(JSON.stringify(response.message["7"][0]["childMessageData"][0]["id"])).to.equal(1);
96
- // expect(JSON.stringify(response.message["7"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
97
-
98
- // // "8": [{"closeChild":true,"pid":11732,"childMessageData":[{"id":"8","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
99
- // expect(JSON.stringify(response.message["8"][0]["closeChild"])).to.equal(true);
100
- // expect(JSON.stringify(response.message["8"][0]["childMessageData"][0]["id"])).to.equal(1);
101
- // expect(JSON.stringify(response.message["8"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
102
-
103
- // // "result":[]
104
- // expect(JSON.stringify(response.result)).to.equal(JSON.stringify([]));
105
- // done();
106
- // process.exit();
26
+ // it('[Test A] Test for cluster function demos', async function () {
27
+
28
+ // var response = await require("./demos.cluster").concurrency;
29
+ // // console.log(response);
30
+
31
+ // expect(200).to.equal(200);
32
+
33
+ // // // "1":[{"closeChild":true,"pid":7468,"childMessageData":[{"id":"1","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
34
+ // // expect(JSON.stringify(response.message["1"][0]["closeChild"])).to.equal(true);
35
+ // // expect(JSON.stringify(response.message["1"][0]["childMessageData"][0]["id"])).to.equal(1);
36
+ // // expect(JSON.stringify(response.message["1"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
37
+
38
+ // // // "2":[{"closeChild":true,"pid":13784,"childMessageData":[{"id":"2","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
39
+ // // expect(JSON.stringify(response.message["2"][0]["closeChild"])).to.equal(true);
40
+ // // expect(JSON.stringify(response.message["2"][0]["childMessageData"][0]["id"])).to.equal(1);
41
+ // // expect(JSON.stringify(response.message["2"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
42
+
43
+ // // // "3":[{"closeChild":true,"pid":872,"childMessageData":[{"id":"3","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
44
+ // // expect(JSON.stringify(response.message["3"][0]["closeChild"])).to.equal(true);
45
+ // // expect(JSON.stringify(response.message["3"][0]["childMessageData"][0]["id"])).to.equal(1);
46
+ // // expect(JSON.stringify(response.message["3"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
47
+
48
+ // // // "4": [{"closeChild":true,"pid":11732,"childMessageData":[{"id":"4","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
49
+ // // expect(JSON.stringify(response.message["4"][0]["closeChild"])).to.equal(true);
50
+ // // expect(JSON.stringify(response.message["4"][0]["childMessageData"][0]["id"])).to.equal(1);
51
+ // // expect(JSON.stringify(response.message["4"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
52
+
53
+ // // // "5":[{"closeChild":true,"pid":7468,"childMessageData":[{"id":"5","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
54
+ // // expect(JSON.stringify(response.message["5"][0]["closeChild"])).to.equal(true);
55
+ // // expect(JSON.stringify(response.message["5"][0]["childMessageData"][0]["id"])).to.equal(1);
56
+ // // expect(JSON.stringify(response.message["5"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
57
+
58
+ // // // "6":[{"closeChild":true,"pid":13784,"childMessageData":[{"id":"6","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
59
+ // // expect(JSON.stringify(response.message["6"][0]["closeChild"])).to.equal(true);
60
+ // // expect(JSON.stringify(response.message["6"][0]["childMessageData"][0]["id"])).to.equal(1);
61
+ // // expect(JSON.stringify(response.message["6"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
62
+
63
+ // // // "7":[{"closeChild":true,"pid":872,"childMessageData":[{"id":"7","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
64
+ // // expect(JSON.stringify(response.message["7"][0]["closeChild"])).to.equal(true);
65
+ // // expect(JSON.stringify(response.message["7"][0]["childMessageData"][0]["id"])).to.equal(1);
66
+ // // expect(JSON.stringify(response.message["7"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
67
+
68
+ // // // "8": [{"closeChild":true,"pid":11732,"childMessageData":[{"id":"8","pid":9744,"message":{"message":"Testing parent data","url":"https://www.google.com"}},{"closeChild":true}],"result":[]}]
69
+ // // expect(JSON.stringify(response.message["8"][0]["closeChild"])).to.equal(true);
70
+ // // expect(JSON.stringify(response.message["8"][0]["childMessageData"][0]["id"])).to.equal(1);
71
+ // // expect(JSON.stringify(response.message["8"][0]["childMessageData"][0]["message"])).to.equal({ "message": "Testing parent data", "url": "https://www.google.com" });
72
+
73
+ // // // "result":[]
74
+ // // expect(JSON.stringify(response.result)).to.equal(JSON.stringify([]));
75
+
107
76
  // });
108
77
 
109
78
  // });
@@ -1,49 +1,53 @@
1
- // /**
2
- // *
3
- // * Package: concurrency.js
4
- // * Author: Ganesh B
5
- // * Description: npm module to work with concurrency - worker threads and worker processes easily using simple functions and script files
6
- // * Install: npm i --save
7
- // * Github: https://github.com/ganeshkbhat/concurrency
8
- // * npmjs Link: https://www.npmjs.com/package/concurrency.js
9
- // * File: test.demos.process.js
10
- // * File Description:
11
- // *
12
- // */
13
-
14
- // /* eslint no-console: 0 */
15
-
16
- // 'use strict';
17
-
18
-
19
- // const expect = require('chai').expect;
20
- // const path = require("path");
21
- // const { _concurrencyProcesses } = require("../index.js");
22
-
23
-
24
- // describe('test-.js::concurrency.js: [Test A] Test Suite for concurrency.js .process in main repo directory', function () {
25
-
26
- // it('[Test A] Test for process function demos', async function (done) {
27
- // var responses;
28
- // let filename = "C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.process.js";
29
- // responses = await _concurrencyProcesses(path.join(filename), { data: { url: "https://www.google.com", message: "Testing data" } });
30
-
31
- // // console.log(responses.message);
32
- // // console.log(responses.result);
33
- // // console.log(responses.message[0].childMessageData);
34
- // // console.log(responses.message[0].childMessageData[0]);
35
- // // console.log(responses.message[0].childMessageData[0].message);
36
- // // console.log(responses.message[0].childMessageData[0].message.url);
37
- // // console.log(responses.message[0].childMessageData[0].message.message);
38
- // // console.log(responses.message[0].childMessageData[0].pid);
39
- // // console.log(responses.message[0].childMessageData[1].closeChild);
40
- // // console.log(responses.message[0].pid);
41
- // // console.log(responses.message[0].closeChild);
42
- // // console.log(responses.message[0].result);
43
-
44
- // expect(true).to.equal(true);
45
- // // done();
46
- // // process.exit();
47
- // });
48
-
49
- // });
1
+ /**
2
+ *
3
+ * Package: concurrency.js
4
+ * Author: Ganesh B
5
+ * Description: npm module to work with concurrency - worker threads and worker processes easily using simple functions and script files
6
+ * Install: npm i --save
7
+ * Github: https://github.com/ganeshkbhat/concurrency
8
+ * npmjs Link: https://www.npmjs.com/package/concurrency.js
9
+ * File: test.demos.process.js
10
+ * File Description:
11
+ *
12
+ */
13
+
14
+ /* eslint no-console: 0 */
15
+
16
+ 'use strict';
17
+
18
+
19
+ const expect = require('chai').expect;
20
+ const path = require("path");
21
+ const { _concurrencyProcesses } = require("../index.js");
22
+
23
+
24
+ describe('test-.js::concurrency.js: [Test A] Test Suite for concurrency.js .process in main repo directory', function () {
25
+
26
+ it('[Test A] Test for process function demos', async function () {
27
+ var responses = await require("./demos.process").concurrency;
28
+
29
+ //
30
+ // { "message": [
31
+ // { "closeChild": true, "pid": 14676,
32
+ // "childMessageData": [
33
+ // { "pid": 3828, "message": "Master Process PID:3828: Hello from Master Process" },
34
+ // { "pid": 3828, "message": { "message": "Testing data", "url": "https://www.google.com" } },
35
+ // { "closeChild": true }],
36
+ // "result": []
37
+ // }],
38
+ // "result": []
39
+ // }
40
+ //
41
+
42
+ expect(!!responses.message).to.equal(true);
43
+ expect(responses.message.length).to.equal(1);
44
+ expect(!!responses.result).to.equal(true);
45
+ expect(responses.message[0].childMessageData.length).to.equal(3);
46
+ expect(!!responses.message[0].result).to.equal(true);
47
+ expect(Object.keys(responses.message[0].childMessageData[0]).length).to.equal(2);
48
+ expect(Object.keys(responses.message[0].childMessageData[1]).length).to.equal(2);
49
+ expect(Object.keys(responses.message[0].childMessageData[2]).length).to.equal(1);
50
+ expect(!!responses.message[0].closeChild).to.equal(true);
51
+ });
52
+
53
+ });
@@ -21,7 +21,7 @@ const expect = require('chai').expect;
21
21
 
22
22
  describe('test-.js::concurrency.js: [Test A] Test Suite for a simple promise', function () {
23
23
 
24
- it('[Test A] Test for promise tests', async function (done) {
24
+ it('[Test A] Test for promise tests', async function () {
25
25
  var result;
26
26
  function testPromise(resolve, reject) {
27
27
  return new Promise(function (resolve, reject) {
@@ -29,9 +29,7 @@ describe('test-.js::concurrency.js: [Test A] Test Suite for a simple promise', f
29
29
  });
30
30
  }
31
31
  result = await testPromise();
32
- console.log(result);
33
32
  expect(result.msg).to.equal("testing");
34
- // done();
35
33
  });
36
34
 
37
35
  });
@@ -11,49 +11,30 @@
11
11
  // *
12
12
  // */
13
13
 
14
- // /* eslint no-console: 0 */
15
-
16
- // 'use strict';
17
-
18
-
19
- // const expect = require('chai').expect;
20
- // const path = require("path");
21
- // const { _concurrencyThreads } = require("../index.js");
22
-
23
-
24
- // describe('test-.js::concurrency.js: [Test A] Test Suite for concurrency.js .threads in main repo directory', function () {
25
-
26
- // it('[Test A] Test for threads ', function (done) {
27
- // var responses;
28
- // _concurrencyThreads(__filename, {
29
- // data: {
30
- // message: "Testing data",
31
- // url: "https://www.google.com"
32
- // },
33
- // childData: "Testing child data"
34
- // }).then((d) => {
35
- // console.log(JSON.stringify(d));
36
- // responses = d;
37
- // done();
38
- // });
39
- // expect(responses).to.equal({
40
- // "message": [
41
- // { "pid": 11660, "message": "\"Hello from child. - Thread: 11660", "threadId": 1 },
42
- // {
43
- // "closeChild": true,
44
- // "pid": 11660,
45
- // "childMessageData": [
46
- // { "pid": 11660, "message": "Hello, world! - Server: 11660" },
47
- // { "closeChild": true }],
48
- // "result": [],
49
- // "threadId": 1
50
- // }
51
- // ],
52
- // "result": []
53
- // });
54
- // done();
55
- // });
56
-
57
- // });
14
+
15
+ /* eslint no-console: 0 */
16
+
17
+ 'use strict';
18
+
19
+
20
+ const expect = require('chai').expect;
21
+ const path = require("path");
22
+ var spawn = require("child_process").spawn;
23
+
24
+ const { _concurrencyThreads } = require("../index.js");
25
+
26
+
27
+ describe('test-.js::concurrency.js: [Test A] Test Suite for concurrency.js .threads in main repo directory', function () {
28
+
29
+ it('[Test A] Test for threads _concurrencyThreads', async function () {
30
+ let responses = await require("./demos.threads").concurrency;
31
+
32
+ expect(Object.keys(responses).length).to.equal(2);
33
+ expect(responses.message.length).to.equal(1);
34
+ // expect(Object.keys(responses.message[0]).length).to.equal(2);
35
+ expect(Object.keys(responses.message[0]).length).to.equal(5);
36
+ });
37
+
38
+ });
58
39
 
59
40