concurrency.js 0.0.1 → 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.
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: Bug report ticket
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Desktop (please complete the following information):**
27
+ - OS: [e.g. iOS]
28
+ - Browser [e.g. chrome, safari]
29
+ - Version [e.g. 22]
30
+
31
+ **Smartphone (please complete the following information):**
32
+ - Device: [e.g. iPhone6]
33
+ - OS: [e.g. iOS8.1]
34
+ - Browser [e.g. stock browser, safari]
35
+ - Version [e.g. 22]
36
+
37
+ **Additional context**
38
+ Add any other context about the problem here.
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: Feature request ticket
3
+ about: Suggest an idea for this project
4
+ title: "[FEATURE] Feature summary description here"
5
+ labels: ''
6
+ assignees: ganeshkbhat
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **Details**
14
+ Any relevant steps
15
+
16
+ **Is your feature request related to a problem? Please describe.**
17
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
18
+
19
+ **Describe the solution you'd like**
20
+ A clear and concise description of what you want to happen.
21
+
22
+ **Describe alternatives you've considered**
23
+ A clear and concise description of any alternative solutions or features you've considered.
24
+
25
+ **Expected behavior**
26
+ A clear and concise description of what you expected to happen.
27
+
28
+ **Screenshots**
29
+ If applicable, add screenshots or wireframe to help explain your feature.
30
+
31
+ **Desktop (please complete the following information):**
32
+ - OS: [e.g. iOS]
33
+ - Browser [e.g. chrome, safari]
34
+ - Version [e.g. 22]
35
+
36
+ **Smartphone (please complete the following information):**
37
+ - Device: [e.g. iPhone6]
38
+ - OS: [e.g. iOS8.1]
39
+ - Browser [e.g. stock browser, safari]
40
+ - Version [e.g. 22]
41
+
42
+ **Additional context**
43
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: General Request ticket
3
+ about: Suggest any other than issue or bug or feature or idea for this project
4
+ title: "[REQUEST] Request summary"
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Please describe your request.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternatives you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the request here.
@@ -0,0 +1,51 @@
1
+ ---
2
+ name: Security Vulnerability / Bug report ticket
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the Security vulnerability / bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **Security Vulerability**
14
+ Describe the security vulnerability.
15
+
16
+ **Security Vulerability Impact**
17
+ Describe the security vulnerability impact.
18
+
19
+ **Security Vulerability Detection or How To Reproduce**
20
+ Describe how the security vulnerability can be detected or reprduced.
21
+
22
+ Steps to reproduce the behavior:
23
+ 1. Go to '...'
24
+ 2. Click on '....'
25
+ 3. Scroll down to '....'
26
+ 4. See error
27
+
28
+ **Expected behavior**
29
+ A clear and concise description of what you expected to happen.
30
+
31
+ **How To Rectify the Security Vulerability Issue**
32
+ Describe How To Rectify the Security Vulerability Issue.
33
+
34
+ Eg: Upgrade package, code section change, feature, changing defaults, etc.
35
+
36
+ **Screenshots**
37
+ If applicable, add screenshots to help explain your problem.
38
+
39
+ **Desktop (please complete the following information):**
40
+ - OS: [e.g. iOS]
41
+ - Browser [e.g. chrome, safari]
42
+ - Version [e.g. 22]
43
+
44
+ **Smartphone (please complete the following information):**
45
+ - Device: [e.g. iPhone6]
46
+ - OS: [e.g. iOS8.1]
47
+ - Browser [e.g. stock browser, safari]
48
+ - Version [e.g. 22]
49
+
50
+ **Additional context**
51
+ Add any other context about the problem here.
package/README.md CHANGED
@@ -1,2 +1,119 @@
1
- # concurrency
1
+ # concurrency.js
2
+
2
3
  npm module to work with concurrency - worker threads and worker processes easily using simple functions and script files
4
+
5
+ Find the demos in the [demos folder](./demos)
6
+
7
+ #### Cluster Methods
8
+
9
+
10
+ `_concurrencyClusters(filename = __filename, num = cpus().length, options = {}, greet = false)`
11
+
12
+ ```
13
+
14
+ const path = require("path");
15
+ let { _concurrencyClusters } = require("concurrency.js");
16
+
17
+ function concurrency() {
18
+ return new Promise(function (resolve, reject) {
19
+ _concurrencyClusters(
20
+ path.join("C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.cluster.js"),
21
+ 8,
22
+ {
23
+ data: {
24
+ data: "Testing parent data",
25
+ url: "https://www.google.com"
26
+ },
27
+ childData: "Test data from child"
28
+ }
29
+ ).then((d) => {
30
+ console.log("Data fetched", JSON.stringify(d));
31
+ resolve(d);
32
+ }).catch((e) => {
33
+ console.log(e.toString());
34
+ reject(e);
35
+ });
36
+ });
37
+ }
38
+ concurrency();
39
+
40
+ ```
41
+
42
+ #### Process Methods
43
+
44
+
45
+ `_concurrencyProcesses(filename = __filename, options = {}, greet = false)`
46
+
47
+ ```
48
+
49
+ const path = require("path");
50
+ let { _concurrencyProcesses } = require("concurrency.js");
51
+ _concurrencyProcesses(
52
+ path.join(
53
+ "C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.process.js"),
54
+ {
55
+ data: {
56
+ message: "Testing data",
57
+ url: "https://www.google.com"
58
+ }
59
+ },
60
+ true
61
+ ).then((d) => { console.log("Data fetched: ", JSON.stringify(d)); })
62
+ .catch((e) => { console.log(e.toString()); setTimeout(() => { process.exit(e); }, 5000) })
63
+
64
+ ```
65
+
66
+ #### Threads Methods
67
+
68
+
69
+ `_concurrencyThreads(filename = __filename, options = {}, greet = false)`
70
+
71
+ ```
72
+
73
+ const path = require("path");
74
+ let { _concurrencyThreads } = require("concurrency.js");
75
+ _concurrencyThreads(
76
+ __filename,
77
+ {
78
+ data: {
79
+ url: "https://www.google.com",
80
+ data: "Testing data"
81
+ },
82
+ childData: "Testing child data"
83
+ },
84
+ true
85
+ ).then((d) => console.log(JSON.stringify(d)));
86
+
87
+ ```
88
+
89
+ #### Thread Async Methods
90
+
91
+
92
+ `_concurrencyThreadsAsync(command, options)`
93
+
94
+
95
+ ```
96
+
97
+ const path = require("path");
98
+ let { _concurrencyThreadsAsync } = require("concurrency.js");
99
+
100
+ let threads = _concurrencyThreadsAsync(
101
+ "C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\demos\\demos.threads.js",
102
+ {
103
+ data: {
104
+ data: "Testing parent data",
105
+ url: "https://www.google.com"
106
+ },
107
+ childData: "Test data from child"
108
+ }
109
+ );
110
+
111
+ ```
112
+
113
+ ### Contributions
114
+
115
+ Contributions, Feature Improvements, Bugs, and Issues are invited. [raising an issue](https://github.com/ganeshkbhat/concurrency.js/issues)
116
+
117
+ # License
118
+
119
+ [MIT License](./LICENSE)
@@ -0,0 +1,22 @@
1
+
2
+ const path = require("path");
3
+ const { _concurrencyClusters } = require("../index.js");
4
+
5
+
6
+ async function cluster() {
7
+ let filename = "C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.cluster.js";
8
+ return _concurrencyClusters(
9
+ path.join(filename),
10
+ // __filename,
11
+ 8,
12
+ {
13
+ data: {
14
+ url: "https://www.google.com",
15
+ message: "Testing parent data"
16
+ },
17
+ childData: "Test data from child"
18
+ }
19
+ )
20
+ }
21
+
22
+ module.exports = cluster;
@@ -0,0 +1,66 @@
1
+
2
+ const path = require("path");
3
+ let { _concurrencyClusters } = require("../index.js");
4
+
5
+
6
+ // console.log(_concurrencyClusters(
7
+ // path.join("C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.process.js"),
8
+ // 8,
9
+ // { url: "https://www.google.com", data: "Testing parent data", childData: "Test data from child" }
10
+ // ).then((d) => {
11
+ // console.log("Data fetched", JSON.stringify(d));
12
+ // }).catch((e) => {
13
+ // console.log(e.toString());
14
+ // }))
15
+
16
+
17
+
18
+
19
+ // async function concurrency() {
20
+ // let result = await _concurrencyClusters(
21
+ // path.join("C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.cluster.js"),
22
+ // 8,
23
+ // { url: "https://www.google.com", data: "Testing parent data", childData: "Test data from child" }
24
+ // )
25
+ // console.log(result);
26
+ // }
27
+
28
+ // function concurrency() {
29
+ // _concurrencyClusters(
30
+ // path.join("C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.cluster.js"),
31
+ // 8,
32
+ // { url: "https://www.google.com", data: "Testing parent data", childData: "Test data from child" }
33
+ // ).then((d) => {
34
+ // console.log("Data fetched", JSON.stringify(d));
35
+ // }).catch((e) => {
36
+ // console.log(e.toString());
37
+ // })
38
+ // }
39
+
40
+ function concurrency() {
41
+ let filename = "C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.cluster.js";
42
+ return new Promise(function (resolve, reject) {
43
+ _concurrencyClusters(
44
+ path.join(filename),
45
+ 8,
46
+ {
47
+ data: {
48
+ message: "Testing parent data",
49
+ url: "https://www.google.com",
50
+ },
51
+ childData: "Test data from child"
52
+ }
53
+ ).then((d) => {
54
+ console.log("Data fetched", JSON.stringify(d));
55
+ resolve(d);
56
+ }).catch((e) => {
57
+ console.log(e.toString());
58
+ reject(e);
59
+ });
60
+ });
61
+ }
62
+
63
+ concurrency();
64
+
65
+ setTimeout(() => console.log(`demo.cluster.js: run file PID ${process.pid}: Interval 2: 10000 `, process.pid), 10000);
66
+ setTimeout(() => console.log(`demo.cluster.js: Closing process ${process.pid}: Timeout 1: 10000 `, process.exit()), 20000);
package/demos/demos.js ADDED
@@ -0,0 +1,21 @@
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: index.js
10
+ * File Description:
11
+ *
12
+ */
13
+
14
+ /* eslint no-console: 0 */
15
+
16
+ 'use strict';
17
+
18
+
19
+ let { _concurrencyThreads, _concurrencyProcesses, _concurrencyClusters, _concurrencyThreadsAsync } = require("../index.js");
20
+ console.log(_concurrencyThreads, _concurrencyProcesses, _concurrencyClusters, _concurrencyThreadsAsync);
21
+
@@ -0,0 +1,37 @@
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: demo.processes.js
10
+ * File Description:
11
+ *
12
+ */
13
+
14
+ /* eslint no-console: 0 */
15
+
16
+ 'use strict';
17
+
18
+
19
+ const path = require("path");
20
+ let { _concurrencyProcesses } = require("../index.js");
21
+
22
+ let filename = "C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.process.js";
23
+ _concurrencyProcesses(
24
+ path.join(filename), {
25
+ data: {
26
+ message: "Testing data",
27
+ url: "https://www.google.com"
28
+ }
29
+ }, true).then((d) => {
30
+ console.log("Data fetched: ", JSON.stringify(d));
31
+ }).catch((e) => {
32
+ console.log(e.toString()); setTimeout(() => { process.exit(e); }, 5000)
33
+ });
34
+
35
+ setTimeout(() => console.log(`demo.processes.js: Run file PID ${process.pid}: Interval 2: 10000 `, process.pid), 10000);
36
+ setTimeout(() => console.log(`demo.processes.js: Closing process ${process.pid}: Timeout 1: 10000 `, process.exit()), 20000);
37
+
@@ -0,0 +1,22 @@
1
+
2
+
3
+ const path = require("path");
4
+ let { _concurrencyThreadsAsync } = require("../index.js");
5
+
6
+ let filename = "C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\demos\\demos.threads.js";
7
+
8
+ let threads = _concurrencyThreadsAsync(filename, {
9
+ data: {
10
+ message: "Testing parent data",
11
+ url: "https://www.google.com"
12
+ },
13
+ childData: "Test data from child"
14
+ });
15
+
16
+ console.log(` STDOUT: console.log(threads.stderr); console.log(threads.stdout); `);
17
+
18
+ console.log(threads.stderr);
19
+ console.log(threads.stdout);
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);
@@ -0,0 +1,40 @@
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: demo.threads.js
10
+ * File Description:
11
+ *
12
+ */
13
+
14
+ /* eslint no-console: 0 */
15
+
16
+ 'use strict';
17
+
18
+ const path = require("path");
19
+ let { _concurrencyThreads } = require("../index.js");
20
+
21
+ // _concurrencyThreads(path.join("C:\\Users\\GB\\Documents\\projects\\requireurl\\concurrency\\src\\worker.threads.js"), { data: { url: "https://www.google.com", message: "Testing data" } });
22
+
23
+
24
+ _concurrencyThreads(__filename, {
25
+ data: {
26
+ url: "https://www.google.com",
27
+ message: "Testing data"
28
+ },
29
+ childData: "Testing child data"
30
+ }, true).then((d) => console.log(JSON.stringify(d)))
31
+ // .catch((e) => { console.log(e.toString()); setTimeout(() => {process.exit(e);}, 5000) })
32
+
33
+ // setTimeout(() => {
34
+ // console.log(`demo.threads.js: Closing process ${process.pid}: Timeout 1: 20000 `, __filename);
35
+ // process.exit(0);
36
+ // }, 20000);
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);
40
+
package/index.js CHANGED
@@ -1,9 +1,9 @@
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
9
  * File: index.js
@@ -16,3 +16,20 @@
16
16
  'use strict';
17
17
 
18
18
 
19
+ const { _concurrencyThreads } = require("./src/worker.threads.js");
20
+ const { _concurrencyProcesses } = require("./src/worker.process.js");
21
+ const { _concurrencyClusters } = require("./src/worker.cluster.js");
22
+ const { _concurrencyThreadsAsync } = require("./src/worker.thread.async.js");
23
+
24
+
25
+ module.exports._concurrencyThreads = _concurrencyThreads;
26
+ module.exports._concurrencyProcesses = _concurrencyProcesses;
27
+ module.exports._concurrencyClusters = _concurrencyClusters;
28
+ module.exports._concurrencyThreadsAsync = _concurrencyThreadsAsync;
29
+
30
+ module.exports.default = {
31
+ _concurrencyThreads,
32
+ _concurrencyProcesses,
33
+ _concurrencyClusters,
34
+ _concurrencyThreadsAsync
35
+ };
package/index.mjs CHANGED
@@ -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: index.mjs
10
10
  * File Description:
11
11
  *
12
12
  */
@@ -15,3 +15,7 @@
15
15
 
16
16
  'use strict';
17
17
 
18
+ import { _concurrencyThreads, _concurrencyProcesses, _concurrencyThreadsAsync, _concurrencyThreadsAsync } from "./index.js";
19
+
20
+ export { _concurrencyThreads, _concurrencyProcesses, _concurrencyClusters, _concurrencyThreadsAsync };
21
+ export default _concurrencyProcesses;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "concurrency.js",
3
- "version": "0.0.1",
4
- "description": "npm module to work with concurrency - worker threads and worker processes easily using simple functions and script files",
3
+ "version": "0.0.3-beta",
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": {
7
7
  "test": "test"
@@ -12,15 +12,21 @@
12
12
  },
13
13
  "devDependencies": {
14
14
  "chai": "^4.3.6",
15
- "mocha": "^10.1.0",
16
- "nsp": "^3.2.1",
17
- "nsp-api": "^1.0.3",
18
- "safe-regex": "^2.1.1",
19
- "sinon": "^14.0.1",
15
+ "mocha": "^10.0.0",
16
+ "npm-check": "^6.0.1",
17
+ "sinon": "^14.0.0",
20
18
  "unimported": "^1.22.0"
21
19
  },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/ganeshkbhat/concurrency.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/ganeshkbhat/concurrency/issues"
26
+ },
27
+ "homepage": "https://github.com/ganeshkbhat/concurrency#readme",
22
28
  "scripts": {
23
- "test": "echo \"Error: no test specified\" && exit 1"
29
+ "test": "mocha --reporter spec --recursive --timeout 60000"
24
30
  },
25
31
  "author": "Ganesh B",
26
32
  "license": "MIT"