concurrency.js 0.0.2 → 0.0.3-beta

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.
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  *
3
- * Package:
3
+ * Package: concurrency.js
4
4
  * Author: Ganesh B
5
- * Description:
6
- * Install: npm i --save
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
7
  * Github: https://github.com/ganeshkbhat/concurrency
8
8
  * npmjs Link: https://www.npmjs.com/package/
9
- * File: index.js
9
+ * File: worker.process.js
10
10
  * File Description:
11
11
  *
12
12
  */
@@ -15,43 +15,114 @@
15
15
 
16
16
  'use strict';
17
17
 
18
+ const path = require("path");
19
+ const fs = require("fs");
20
+ const { sign } = require("crypto");
18
21
 
19
- process.on('message', function (contents) {
20
- return contents.callback(contents);
21
- }.bind(contents, process));
22
-
23
- // setInterval(() => {
24
- // process.send("Message from parent:");
25
- // }, 1000);
26
- //
27
- // process.on('exit', function (code) {
28
- // setTimeout(function () {
29
- // console.log("This will not run");
30
- // }, 0);
31
- // console.log('About to exit with code:', code);
32
- // });
33
- //
34
- //
35
- // // Printing to console
36
- // process.stdout.write("Hello World!" + "\n");
37
- //
38
- // // Reading passed parameter
39
- // process.argv.forEach(function(val, index, array) {
40
- // console.log(index + ': ' + val);
41
- // });
42
- //
43
- // // Getting executable path
44
- // console.log(process.execPath);
45
- //
46
- // // Platform Information
47
- // console.log(process.platform);
48
- //
49
- // // Print the current directory
50
- // console.log('Current directory: ' + process.cwd());
51
- //
52
- // // Print the process version
53
- // console.log('Current version: ' + process.version);
54
- //
55
- // // Print the memory usage
56
- // console.log(process.memoryUsage());
57
- //
22
+
23
+ function _concurrencyProcesses(filename = __filename, options = {}, greet = false) {
24
+ var messageData = [], childMessageData = [], result = [];
25
+ if (!options.handlers) {
26
+ options["handlers"] = {};
27
+ }
28
+ if (process.env.FORK) {
29
+ if (!options.callback) {
30
+ options["callback"] = function (data) {
31
+ childMessageData.push(data);
32
+ if (!!process.env.handlers.childMessage) {
33
+ const childCBFunction = require(process.env.handlers.childMessage);
34
+ result.push({ message: childCBFunction(data), pid: process.pid, event: "message" });
35
+ }
36
+ if (!!data.closeChild) {
37
+ process.send({ closeChild: true, pid: process.pid, childMessageData: childMessageData, result: result });
38
+ }
39
+ }
40
+ }
41
+
42
+ // process.stdout.on("message", console.log);
43
+ // process.stdin.on("message", console.log);
44
+ // process.stderr.on("message", console.log);
45
+
46
+ process.on("message", options.callback);
47
+
48
+ process.on("exit", (code) => {
49
+ // console.log(`worker.process.js: _concurrencyProcesses: Child Process PID:${process.pid}: EXIT CODE ${code} CHILD: `, childMessageData);
50
+ if (!!process.env.handlers.childExit) {
51
+ const cbFunction = require(process.env.handlers.childExit);
52
+ result.push({ message: cbFunction(code), pid: process.pid, event: "exit" });
53
+ }
54
+ });
55
+
56
+ if (!!greet) {
57
+ process.send({ pid: process.pid, message: `Child Process PID:${process.pid}: Hello from Child Process` });
58
+ }
59
+
60
+ (!!process.env.childData) ? child.send({ pid: process.pid, message: process.env.childData }) : null;
61
+
62
+ } else {
63
+
64
+ return new Promise((resolve, reject) => {
65
+ const { fork, spawn } = require("child_process");
66
+ const controller = new AbortController();
67
+ const { signal } = controller;
68
+
69
+ const child = fork(filename, {
70
+ signal: signal, silent: false, env: {
71
+ ...process.env, FORK: 1, childData: options.childData, handlers: { ...options.handlers }
72
+ }
73
+ });
74
+
75
+ child.on("error", (e) => {
76
+ if (!!options.handlers.error) {
77
+ const cbFunction = require(options.handlers.error);
78
+ result.push({ message: cbFunction(e), pid: process.pid, event: "error" });
79
+ }
80
+ reject(e);
81
+ });
82
+
83
+ child.on("close", function (code, signal) {
84
+ let pid = child.pid, connected = child.connected;
85
+ if (!!options.handlers.close) {
86
+ const cbFunction = require(options.handlers.close);
87
+ result.push({ message: cbFunction(code, signal, pid, connected), pid: process.pid, event: "close" });
88
+ }
89
+ });
90
+
91
+ child.on("message", (data) => {
92
+ messageData.push(data);
93
+ if (!!options.handlers.message) {
94
+ const cbFunction = require(options.handlers.message);
95
+ result.push({ message: cbFunction(data), pid: process.pid, event: "message" });
96
+ }
97
+ if (!!data.closeChild) {
98
+ //
99
+ // try {
100
+ // // Stops the child process on message from child
101
+ // // Getting Error:
102
+ // // AbortError: The operation was aborted
103
+ // controller.abort();
104
+ // } catch (e) {
105
+ // child.kill(0);
106
+ // } finally {
107
+ // resolve({ messageData, result });
108
+ // }
109
+ //
110
+ child.kill(0);
111
+ resolve({ message: messageData, result: result });
112
+ }
113
+ });
114
+
115
+ if (!!greet) {
116
+ child.send({ pid: process.pid, message: `Master Process PID:${process.pid}: Hello from Master Process` });
117
+ }
118
+ options.data ? child.send({ pid: process.pid, message: options.data }) : null;
119
+ child.send({ closeChild: true });
120
+ });
121
+ }
122
+ }
123
+
124
+ if (process.env.FORK) {
125
+ _concurrencyProcesses();
126
+ }
127
+
128
+ module.exports._concurrencyProcesses = _concurrencyProcesses;
@@ -0,0 +1,84 @@
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.threads.async.js
10
+ * File Description:
11
+ *
12
+ * https://github.com/danday74/shelljs.exec
13
+ *
14
+ *
15
+ */
16
+
17
+ /* eslint no-console: 0 */
18
+
19
+ 'use strict';
20
+
21
+ var cp = require('child_process');
22
+
23
+ function isObject(obj) {
24
+ return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
25
+ }
26
+
27
+ function toBoolean(bool) {
28
+ if (bool === 'false') bool = false;
29
+ return !!bool;
30
+ }
31
+
32
+ function normaliseOptions(options) {
33
+
34
+ var DEFAULTS = Object.freeze({
35
+ encoding: 'utf8',
36
+ silent: false
37
+ })
38
+
39
+ if (!isObject(options)) {
40
+ options = {}
41
+ } else {
42
+ if (typeof options.silent !== 'undefined') {
43
+ options.silent = toBoolean(options.silent);
44
+ }
45
+ }
46
+
47
+ options = Object.assign({}, DEFAULTS, options);
48
+
49
+ if (options.silent && typeof options.stdio === 'undefined') {
50
+ options.stdio = 'pipe';
51
+ }
52
+
53
+ return options;
54
+ }
55
+
56
+ function _concurrencyThreadsAsync(command, options) {
57
+
58
+ options = normaliseOptions(options);
59
+ var error, stdout, stderr, code, ok;
60
+
61
+ try {
62
+ error = null
63
+ stdout = cp.execSync("node " + command, options)
64
+ stderr = ''
65
+ code = 0
66
+ ok = true
67
+ } catch (e) {
68
+ error = e
69
+ stdout = e.stdout
70
+ stderr = e.stderr
71
+ code = e.status || /* istanbul ignore next */ 1
72
+ ok = false
73
+ }
74
+
75
+ return {
76
+ error: error,
77
+ stdout: stdout,
78
+ stderr: stderr,
79
+ code: code,
80
+ ok: ok
81
+ }
82
+ }
83
+
84
+ module.exports._concurrencyThreadsAsync = _concurrencyThreadsAsync;
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  *
3
- * Package:
3
+ * Package: concurrency.js
4
4
  * Author: Ganesh B
5
- * Description:
6
- * Install: npm i --save
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
7
  * Github: https://github.com/ganeshkbhat/concurrency
8
8
  * npmjs Link: https://www.npmjs.com/package/
9
- * File: index.js
9
+ * File: worker.threads.js
10
10
  * File Description:
11
11
  *
12
12
  */
@@ -15,9 +15,168 @@
15
15
 
16
16
  'use strict';
17
17
 
18
+ const path = require('path');
19
+ const fs = require('fs');
18
20
 
19
- const { parentPort } = require("worker_threads");
20
21
 
21
- parentPort.on("message", function (contents) {
22
- return contents.callback(contents, parentPort);
23
- }.bind(contents, parentPort));
22
+
23
+ function _concurrencyThreads(filename = __filename, options = {}, greet = false) {
24
+ const { Worker, isMainThread, parentPort } = require('worker_threads');
25
+
26
+ var messageData = [], childMessageData = [], result = [];
27
+ if (!options.handlers) { options["handlers"] = {}; }
28
+
29
+ return new Promise((resolve, reject) => {
30
+ if (isMainThread) {
31
+ // return new Promise((resolve, reject) => {
32
+ const worker = new Worker(filename);
33
+ if (!!greet) {
34
+ worker.postMessage({ pid: process.pid, message: `Hello, world! - Server: ${process.pid}` });
35
+ }
36
+
37
+ worker.on("connection", (e) => {
38
+ // console.log(`Main thread ${process.pid} due to connection event`, e.toString());
39
+ if (!!options.handlers.connection) {
40
+ const cbFunction = require(options.handlers.connection);
41
+ result.push({ message: cbFunction(e), pid: process.pid, event: "connection" });
42
+ }
43
+ });
44
+
45
+ worker.on("message", function (mainData) {
46
+ messageData.push({ ...mainData, threadId: worker.threadId });
47
+ if (!!options.handlers.message) {
48
+ const cbFunction = require(options.handlers.message);
49
+ result.push({ message: cbFunction(mainData), pid: process.pid, event: "message" });
50
+ }
51
+ if (!!mainData.closeChild) {
52
+ mainData = { ...mainData, threadId: worker.threadId };
53
+ childMessageData.push(mainData);
54
+ try {
55
+ worker.unref();
56
+ } catch (e) {
57
+ worker.terminate();
58
+ }
59
+ resolve({ message: messageData, result: result });
60
+ }
61
+ // console.log(`demo.threads.js:_concurrencyThreads: Main Thread PID ${process.pid}, filename: ${filename}, data: ${mainData}`);
62
+ });
63
+
64
+ worker.on("online", () => {
65
+ if (!!options.handlers.online) {
66
+ const cbFunction = require(options.handlers.online);
67
+ result.push({ message: cbFunction(), pid: process.pid, event: "online" });
68
+ }
69
+ });
70
+
71
+ worker.on("error", (e) => {
72
+ if (!!options.handlers.error) {
73
+ const cbFunction = require(options.handlers.error);
74
+ result.push({ message: cbFunction(e), pid: process.pid, event: "error" });
75
+ }
76
+ reject(e)
77
+ });
78
+
79
+ worker.on("messageerror", (e) => {
80
+ if (!!options.handlers.messageerror) {
81
+ const cbFunction = require(options.handlers.messageerror);
82
+ result.push({ message: cbFunction(e), pid: process.pid, event: "messageerror" });
83
+ }
84
+ reject(e)
85
+ });
86
+
87
+ worker.on("close", (e) => {
88
+ console.log(`demo.threads.js:_concurrencyThreads: Main Thread PID ${process.pid} threadID:${worker.threadId} : Closing main thread `, e.toString(), messageData);
89
+ worker.unref();
90
+ if (!!options.handlers.close) {
91
+ const cbFunction = require(options.handlers.close);
92
+ result.push({ message: cbFunction(e), pid: process.pid, event: "close" });
93
+ }
94
+ // resolve({ messageData, result });
95
+ });
96
+
97
+ worker.on("exit", (code) => {
98
+ console.log(`demo.threads.js:_concurrencyThreads: Main Thread PID ${process.pid} threadID:${worker.threadId}, filename: ${filename}, ExitCode: ${code}, messageData`, messageData);
99
+ if (!!options.handlers.exit) {
100
+ const cbFunction = require(options.handlers.exit);
101
+ result.push({ message: cbFunction(code), pid: process.pid, event: "exit" });
102
+ }
103
+ if (code !== 0) {
104
+ reject(new Error(`Worker (PID ${process.pid}) threadID:${worker.threadId} stopped with exit code ${code}`));
105
+ }
106
+ // reject(new Error(`Worker (PID ${process.pid}) threadID:${worker.threadId} stopped with exit code ${code}`));
107
+ });
108
+ worker.postMessage({ closeChild: true });
109
+ // });
110
+
111
+ } else {
112
+
113
+ if (!options.callback) {
114
+
115
+ // options.callback = function (contents) {
116
+ // console.log("Testing worker");
117
+ // const { get } = (options.protocol === "https") ? require("https") : require("http");
118
+ // get(contents.url, (res) => {
119
+ // let result = "";
120
+ // res.on("data", (chunk) => result += chunk);
121
+ // res.on("end", () => {
122
+ // parentPort.postMessage(result);
123
+ // });
124
+ // }).on("error", (err) => parentPort.postMessage(err));
125
+ // }.bind(null, null, options);
126
+
127
+ options.callback = function (mainData) {
128
+ // return options.callback(data, parentPort);
129
+ // console.log(`demo.threads.js:_concurrencyThreads: Thread: Child Thread PID ${process.pid}, messageData: `, mainData);
130
+ childMessageData.push(mainData);
131
+ if (!!options.handlers.childMessage) {
132
+ const childCBFunction = require(options.handlers.childMessage);
133
+ result.push({ message: childCBFunction(mainData), pid: process.pid, event: "message" });
134
+ }
135
+ if (!!mainData.closeChild) {
136
+ parentPort.postMessage({ closeChild: true, pid: process.pid, childMessageData: childMessageData, result: result });
137
+ }
138
+ }
139
+ }
140
+
141
+ parentPort.on("connection", (e) => {
142
+ console.log(`demo.threads.js:_concurrencyThreads: Thread PID ${process.pid}: Child thread due to connection event `, e.toString())
143
+ if (!!options.handlers.childConnection) {
144
+ const childCBFunction = require(options.handlers.childConnection);
145
+ result.push({ message: childCBFunction(e), pid: process.pid, event: "connection" });
146
+ }
147
+ });
148
+
149
+ parentPort.on("message", options.callback);
150
+
151
+ parentPort.on("error", (e) => {
152
+ console.log(`demo.threads.js:_concurrencyThreads: Thread PID ${process.pid}:Closing child thread due to error`, e.toString());
153
+ if (!!options.handlers.childError) {
154
+ const cbFunction = require(options.handlers.childError);
155
+ result.push({ message: cbFunction(e), pid: process.pid, event: "error" });
156
+ }
157
+ });
158
+
159
+ parentPort.on("messageerror", (e) => {
160
+ console.log(`demo.threads.js:_concurrencyThreads: Thread PID ${process.pid}: Closing child thread due to messageerror`, e.toString());
161
+ if (!!options.handlers.messageerror) {
162
+ const cbFunction = require(options.handlers.messageerror);
163
+ result.push({ message: cbFunction(e), pid: process.pid, event: "messageerror" });
164
+ }
165
+ });
166
+
167
+ parentPort.on("close", (e) => {
168
+ console.log(`demo.threads.js:_concurrencyThreads: Thread PID ${process.pid}: Closing child thread due to close event`, e.toString());
169
+ if (!!options.handlers.close) {
170
+ const cbFunction = require(options.handlers.close);
171
+ result.push({ message: cbFunction(e), pid: process.pid, event: "close" });
172
+ }
173
+ });
174
+
175
+ if (!!greet) {
176
+ parentPort.postMessage({ pid: process.pid, message: `"Hello from child. - Thread: ${process.pid}` });
177
+ }
178
+ }
179
+ });
180
+ }
181
+
182
+ module.exports._concurrencyThreads = _concurrencyThreads;
@@ -5,7 +5,7 @@
5
5
  // * Description:
6
6
  // * Install: npm i --save
7
7
  // * Github: https://github.com/ganeshkbhat/concurrency
8
- // * npmjs Link: https://www.npmjs.com/package/
8
+ // * npmjs Link: https://www.npmjs.com/package/concurrency.js
9
9
  // * File: index.js
10
10
  // * File Description:
11
11
  // *
@@ -18,7 +18,7 @@
18
18
 
19
19
  // const expect = require('chai').expect;
20
20
 
21
- // describe('test-.mjs::require-urls: Test Suite for require-urls Files', function() {
21
+ // describe('test-.mjs::concurrency.js: Test Suite for concurrency.js Files', function() {
22
22
 
23
23
 
24
24
  // before(async function(){
@@ -26,7 +26,7 @@
26
26
  // });
27
27
 
28
28
 
29
- // describe ('test-.js::require-urls: [Test A] Test Suite for require-urls in main repo directory', function() {
29
+ // describe ('test-.js::concurrency.js: [Test A] Test Suite for concurrency.js in main repo directory', function() {
30
30
  // // it('[Test A] Test for ', function(done){
31
31
  // // expect(200).to.equal(200);
32
32
  // // done();
@@ -0,0 +1,109 @@
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
+ // 'use strict';
17
+
18
+
19
+ // const expect = require('chai').expect;
20
+ // const path = require("path");
21
+
22
+ // const { _concurrencyClusters } = require("../index.js");
23
+
24
+ // describe('test-.js::concurrency.js: [Test A] Test Suite for concurrency.js cluster in main repo directory', function () {
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();
107
+ // });
108
+
109
+ // });
@@ -0,0 +1,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 (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
+ // });