concurrency.js 0.0.3 → 0.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.
Files changed (41) hide show
  1. package/.todo +1 -1
  2. package/README.md +86 -105
  3. package/demos/concurrency.async.js +22 -0
  4. package/demos/concurrency.process.js +24 -0
  5. package/demos/concurrency.threaded.js +25 -0
  6. package/demos/libmap.js +30 -0
  7. package/index.js +12 -46
  8. package/package.json +8 -4
  9. package/tasks.async.js +72 -0
  10. package/tasks.process.js +65 -0
  11. package/tasks.thread.js +92 -0
  12. package/test/test.process.js +85 -0
  13. package/test/test.promise.js +86 -0
  14. package/test/test.thread.js +86 -0
  15. package/worker.js +24 -0
  16. package/worker_process.js +29 -0
  17. package/demos/cluster.js +0 -22
  18. package/demos/demos.cluster.js +0 -66
  19. package/demos/demos.js +0 -21
  20. package/demos/demos.process.js +0 -37
  21. package/demos/demos.threads.async.js +0 -22
  22. package/demos/demos.threads.js +0 -40
  23. package/docs/Concurrency.js.Process.jpg +0 -0
  24. package/docs/Concurrency.js.Process.pdf +0 -0
  25. package/docs/Concurrency.js.Threads.jpg +0 -0
  26. package/docs/Concurrency.js.Threads.pdf +0 -0
  27. package/index.mjs +0 -39
  28. package/src/worker.cluster.js +0 -122
  29. package/src/worker.cluster.threads.js +0 -20
  30. package/src/worker.process.js +0 -128
  31. package/src/worker.thread.async.js +0 -84
  32. package/src/worker.threads.js +0 -181
  33. package/test/_.test-template.js +0 -44
  34. package/test/demos.cluster.js +0 -46
  35. package/test/demos.process.js +0 -42
  36. package/test/demos.threads.js +0 -43
  37. package/test/test_demos_cluster.js +0 -78
  38. package/test/test_demos_process.js +0 -53
  39. package/test/test_demos_promise.js +0 -36
  40. package/test/test_demos_threads.js +0 -40
  41. package/test/test_demos_threads_async.js +0 -68
@@ -1,122 +0,0 @@
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.process.js
10
- * File Description:
11
- *
12
- */
13
-
14
- /* eslint no-console: 0 */
15
-
16
- 'use strict';
17
-
18
- const cluster = require("node:cluster");
19
- const http = require("node:http");
20
- const { cpus } = require("node:os");
21
- const process = require("node:process");
22
-
23
- function _concurrencyClusters(filename = __filename, num = cpus().length, options = {}, greet = false) {
24
- var worker, workers = {}, result = [];
25
- var messageData = {}, childMessageData = [];
26
-
27
- if (!options.handlers) {
28
- options["handlers"] = {};
29
- }
30
-
31
- return new Promise((resolve, reject) => {
32
- if (cluster.isPrimary) {
33
- num = num || cpus().length;
34
- for (let i = 0; i < num; i++) {
35
- cluster.fork(filename, { env: { ...process.env, FORK: 1, childData: options.childData, handlers: { ...options.handlers } } });
36
- }
37
-
38
- for (const id in cluster.workers) {
39
- messageData[id] = [];
40
- cluster.workers[id].on("message", (msg) => {
41
- if (!messageData[id]) {
42
- messageData[id] = [];
43
- }
44
- messageData[id].push(msg);
45
- if (!!options.handlers.message) {
46
- const cbFunction = require(options.handlers.message);
47
- result.push({ return: cbFunction(msg), id: id, pid: process.pid, event: "message" });
48
- }
49
- if (!!msg.closeChild) {
50
- childMessageData.push(msg);
51
- cluster.workers[id].disconnect();
52
- }
53
- if (!Object.keys(cluster.workers).length) {
54
- resolve({ message: messageData, result: result });
55
- }
56
- });
57
-
58
- if (!!greet) {
59
- cluster.workers[id].send({ pid: process.pid, message: "Message from Parent: " + process.pid.toString() });
60
- }
61
-
62
- (!!options.data) ? cluster.workers[id].send({ id: id, pid: process.pid, message: options.data }) : null;
63
-
64
- cluster.workers[id].on("error", function (e) {
65
- if (!!options.handlers.error) {
66
- const cbFunction = require(options.handlers.error);
67
- result.push({ return: cbFunction(e), id: id, pid: process.pid, event: "error" });
68
- }
69
- reject(e);
70
- });
71
-
72
- cluster.workers[id].on("close", function (code, signal) {
73
- if (!!options.handlers.close) {
74
- let connected = cluster.workers[id].isConnected();
75
- const cbFunction = require(options.handlers.close);
76
- // result.push(cbFunction(code, signal, pid, connected));
77
- result.push({ return: cbFunction(code, signal, pid, connected), id: id, pid: process.pid, event: "close" });
78
- }
79
- });
80
-
81
- cluster.workers[id].on("exit", (code) => {
82
- if (!!options.handlers.exit) {
83
- const cbFunction = require(options.handlers.exit);
84
- result.push({ return: cbFunction(code), id: id, pid: process.pid, event: "exit" });
85
- }
86
- if (!Object.keys(cluster.workers).length) {
87
- // console.log("exit called");
88
- }
89
- });
90
-
91
- cluster.workers[id].send({ closeChild: true })
92
- }
93
- } else if (cluster.isWorker) {
94
- // } else {
95
- // return new Promise((resolve, reject) => {
96
- process.on("message", (msg) => {
97
- childMessageData.push(msg);
98
- // if (!!process.env.handlers.childMessage) {
99
- // const childCBFunction = require(process.env.handlers.childMessage);
100
- // result.push({ return: cbFunction(msg), pid: process.pid, event: "message" });
101
- // }
102
- if (!!msg.closeChild) {
103
- process.send({ closeChild: true, pid: process.pid, childMessageData: childMessageData, result: result });
104
- }
105
- });
106
-
107
- if (!!greet) {
108
- process.send({ pid: process.pid, message: "Message from worker: " + process.pid.toString() });
109
- }
110
-
111
- (!!process.env.childData) ? child.send({ pid: process.pid, message: process.env.childData }) : null;
112
- }
113
- });
114
-
115
- }
116
-
117
- if (process.env.FORK) {
118
- _concurrencyClusters();
119
- }
120
-
121
-
122
- module.exports._concurrencyClusters = _concurrencyClusters;
@@ -1,20 +0,0 @@
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
-
@@ -1,128 +0,0 @@
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.process.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
- const { sign } = require("crypto");
21
-
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;
@@ -1,84 +0,0 @@
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,181 +0,0 @@
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.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
-
21
- function _concurrencyThreads(filename = __filename, options = {}, greet = false) {
22
- const { Worker, isMainThread, parentPort } = require('worker_threads');
23
-
24
- var messageData = [], childMessageData = [], result = [];
25
- if (!options.handlers) { options["handlers"] = {}; }
26
-
27
- return new Promise((resolve, reject) => {
28
- if (isMainThread) {
29
- // return new Promise((resolve, reject) => {
30
- const worker = new Worker(filename);
31
- if (!!greet) {
32
- worker.postMessage({ pid: process.pid, message: `Hello, world! - Server: ${process.pid}` });
33
- }
34
-
35
- worker.on("connection", (e) => {
36
- // console.log(`Main thread ${process.pid} due to connection event`, e.toString());
37
- if (!!options.handlers.connection) {
38
- const cbFunction = require(options.handlers.connection);
39
- result.push({ message: cbFunction(e), pid: process.pid, event: "connection" });
40
- }
41
- });
42
-
43
- worker.on("message", function (mainData) {
44
- messageData.push({ ...mainData, threadId: worker.threadId });
45
- if (!!options.handlers.message) {
46
- const cbFunction = require(options.handlers.message);
47
- result.push({ message: cbFunction(mainData), pid: process.pid, event: "message" });
48
- }
49
- if (!!mainData.closeChild) {
50
- mainData = { ...mainData, threadId: worker.threadId };
51
- childMessageData.push(mainData);
52
- try {
53
- worker.unref();
54
- } catch (e) {
55
- worker.terminate();
56
- }
57
- resolve({ message: messageData, result: result });
58
- }
59
- // console.log(`demo.threads.js:_concurrencyThreads: Main Thread PID ${process.pid}, filename: ${filename}, data: ${mainData}`);
60
- });
61
-
62
- worker.on("online", () => {
63
- if (!!options.handlers.online) {
64
- const cbFunction = require(options.handlers.online);
65
- result.push({ message: cbFunction(), pid: process.pid, event: "online" });
66
- }
67
- });
68
-
69
- worker.on("error", (e) => {
70
- if (!!options.handlers.error) {
71
- const cbFunction = require(options.handlers.error);
72
- result.push({ message: cbFunction(e), pid: process.pid, event: "error" });
73
- }
74
- reject({ e, result });
75
- });
76
-
77
- worker.on("messageerror", (e) => {
78
- if (!!options.handlers.messageerror) {
79
- const cbFunction = require(options.handlers.messageerror);
80
- result.push({ message: cbFunction(e), pid: process.pid, event: "messageerror" });
81
- }
82
- reject({ e, result });
83
- });
84
-
85
- worker.on("close", (e) => {
86
- console.log(`demo.threads.js:_concurrencyThreads: Main Thread PID ${process.pid} threadID:${worker.threadId} : Closing main thread `, e.toString(), messageData);
87
- worker.unref();
88
- if (!!options.handlers.close) {
89
- const cbFunction = require(options.handlers.close);
90
- result.push({ message: cbFunction(e), pid: process.pid, event: "close" });
91
- }
92
- reject({ e, result });
93
- });
94
-
95
- worker.on("exit", (code) => {
96
- console.log(`demo.threads.js:_concurrencyThreads: Main Thread PID ${process.pid} threadID:${worker.threadId}, filename: ${filename}, ExitCode: ${code}, messageData`, messageData);
97
- if (!!options.handlers.exit) {
98
- const cbFunction = require(options.handlers.exit);
99
- result.push({ message: cbFunction(code), pid: process.pid, event: "exit" });
100
- }
101
- if (code !== 0) {
102
- reject(new Error(`Worker (PID ${process.pid}) threadID:${worker.threadId} stopped with exit code ${code}`));
103
- }
104
- // reject(new Error(`Worker (PID ${process.pid}) threadID:${worker.threadId} stopped with exit code ${code}`));
105
- });
106
-
107
- worker.postMessage({ closeChild: true });
108
- // });
109
-
110
- } else {
111
-
112
- if (!options.callback) {
113
-
114
- // options.callback = function (contents) {
115
- // console.log("Testing worker");
116
- // const { get } = (options.protocol === "https") ? require("https") : require("http");
117
- // get(contents.url, (res) => {
118
- // let result = "";
119
- // res.on("data", (chunk) => result += chunk);
120
- // res.on("end", () => {
121
- // parentPort.postMessage(result);
122
- // });
123
- // }).on("error", (err) => parentPort.postMessage(err));
124
- // }.bind(null, null, options);
125
-
126
- options.callback = function (mainData) {
127
- // return options.callback(data, parentPort);
128
- // console.log(`demo.threads.js:_concurrencyThreads: Thread: Child Thread PID ${process.pid}, messageData: `, mainData);
129
- childMessageData.push(mainData);
130
- if (!!options.handlers.childMessage) {
131
- const childCBFunction = require(options.handlers.childMessage);
132
- result.push({ message: childCBFunction(mainData), pid: process.pid, event: "message" });
133
- }
134
- if (!!mainData.closeChild) {
135
- parentPort.postMessage({ closeChild: true, pid: process.pid, childMessageData: childMessageData, result: result });
136
- }
137
- }
138
- }
139
-
140
- parentPort.on("connection", (e) => {
141
- console.log(`demo.threads.js:_concurrencyThreads: Thread PID ${process.pid}: Child thread due to connection event `, e.toString())
142
- if (!!options.handlers.childConnection) {
143
- const childCBFunction = require(options.handlers.childConnection);
144
- result.push({ message: childCBFunction(e), pid: process.pid, event: "connection" });
145
- }
146
- });
147
-
148
- parentPort.on("message", options.callback);
149
-
150
- parentPort.on("error", (e) => {
151
- console.log(`demo.threads.js:_concurrencyThreads: Thread PID ${process.pid}:Closing child thread due to error`, e.toString());
152
- if (!!options.handlers.childError) {
153
- const cbFunction = require(options.handlers.childError);
154
- result.push({ message: cbFunction(e), pid: process.pid, event: "error" });
155
- }
156
- });
157
-
158
- parentPort.on("messageerror", (e) => {
159
- console.log(`demo.threads.js:_concurrencyThreads: Thread PID ${process.pid}: Closing child thread due to messageerror`, e.toString());
160
- if (!!options.handlers.messageerror) {
161
- const cbFunction = require(options.handlers.messageerror);
162
- result.push({ message: cbFunction(e), pid: process.pid, event: "messageerror" });
163
- }
164
- });
165
-
166
- parentPort.on("close", (e) => {
167
- console.log(`demo.threads.js:_concurrencyThreads: Thread PID ${process.pid}: Closing child thread due to close event`, e.toString());
168
- if (!!options.handlers.close) {
169
- const cbFunction = require(options.handlers.close);
170
- result.push({ message: cbFunction(e), pid: process.pid, event: "close" });
171
- }
172
- });
173
-
174
- if (!!greet) {
175
- parentPort.postMessage({ pid: process.pid, message: `"Hello from child. - Thread: ${process.pid}` });
176
- }
177
- }
178
- });
179
- }
180
-
181
- module.exports._concurrencyThreads = _concurrencyThreads;
@@ -1,44 +0,0 @@
1
- // /**
2
- // *
3
- // * Package:
4
- // * Author: Ganesh B
5
- // * Description:
6
- // * Install: npm i --save
7
- // * Github: https://github.com/ganeshkbhat/concurrency
8
- // * npmjs Link: https://www.npmjs.com/package/concurrency.js
9
- // * File: index.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
-
21
- // describe('test-.mjs::concurrency.js: Test Suite for concurrency.js Files', function() {
22
-
23
-
24
- // before(async function(){
25
- //
26
- // });
27
-
28
-
29
- // describe ('test-.js::concurrency.js: [Test A] Test Suite for concurrency.js in main repo directory', function() {
30
- // // it('[Test A] Test for ', function(done){
31
- // // expect(200).to.equal(200);
32
- // // done();
33
- // // });
34
-
35
- // it('[Test A] Test for ', function(done) {
36
- // expect(100).to.equal(100);
37
- // done();
38
- // });
39
-
40
- // });
41
-
42
-
43
- // });
44
-
@@ -1,46 +0,0 @@
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();
@@ -1,42 +0,0 @@
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();