node-worker-pool-lite 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,13 +1,16 @@
1
- # Worker Pool
1
+ # Node Worker Pool Lite
2
+
3
+ [![npm version](https://img.shields.io/npm/v/node-worker-pool-lite.svg)](https://www.npmjs.com/package/node-worker-pool-lite)
4
+ [![license](https://img.shields.io/npm/l/node-worker-pool-lite.svg)](https://github.com/armanmikoyan/node-worker-pool/blob/main/LICENSE)
2
5
 
3
6
  A lightweight Node.js `worker_threads` pool with callback and Promise APIs.
4
7
 
5
- Worker Pool helps you move CPU-heavy work off the main event loop while keeping a small, predictable API. It supports named worker tasks, a fixed-size worker pool, queued jobs, worker replacement after failures, and TypeScript declarations.
8
+ Node Worker Pool Lite helps you move CPU-heavy work off the main event loop while keeping a small, predictable API. It supports named worker tasks, a fixed-size worker pool, queued jobs, worker replacement after failures, and TypeScript declarations.
6
9
 
7
10
  ## Features
8
11
 
9
12
  - Callback-first API from the main package entrypoint.
10
- - Promise API from `worker-pool/promise`.
13
+ - Promise API from `node-worker-pool-lite/promise`.
11
14
  - Named task handlers inside worker files.
12
15
  - Automatic task queueing when all workers are busy.
13
16
  - Worker error propagation to callbacks or rejected promises.
@@ -22,13 +25,7 @@ Worker Pool helps you move CPU-heavy work off the main event loop while keeping
22
25
  ## Installation
23
26
 
24
27
  ```sh
25
- npm install worker-pool
26
- ```
27
-
28
- If you publish this under a scoped package name, install it with your final package name instead:
29
-
30
- ```sh
31
- npm install @your-username/worker-pool
28
+ npm install node-worker-pool-lite
32
29
  ```
33
30
 
34
31
  ## Quick Start
@@ -37,7 +34,7 @@ Create a worker file with named task handlers:
37
34
 
38
35
  ```js
39
36
  // worker.js
40
- import { createWorkerHandler } from 'worker-pool';
37
+ import { createWorkerHandler } from 'node-worker-pool-lite';
41
38
 
42
39
  createWorkerHandler({
43
40
  double(value) {
@@ -54,7 +51,7 @@ Run tasks with the callback API:
54
51
 
55
52
  ```js
56
53
  // index.js
57
- import { WorkerPool } from 'worker-pool';
54
+ import { WorkerPool } from 'node-worker-pool-lite';
58
55
 
59
56
  const pool = new WorkerPool(new URL('./worker.js', import.meta.url), {
60
57
  size: 4,
@@ -74,10 +71,10 @@ pool.run('double', 21, async (error, result) => {
74
71
 
75
72
  ## Promise API
76
73
 
77
- Import from `worker-pool/promise` when you prefer `async` / `await`:
74
+ Import from `node-worker-pool-lite/promise` when you prefer `async` / `await`:
78
75
 
79
76
  ```js
80
- import { WorkerPool } from 'worker-pool/promise';
77
+ import { WorkerPool } from 'node-worker-pool-lite/promise';
81
78
 
82
79
  const pool = new WorkerPool(new URL('./worker.js', import.meta.url), {
83
80
  size: 4,
@@ -96,7 +93,7 @@ try {
96
93
  Workers are registered with `createWorkerHandler()`. Each key is the task name used by `pool.run()`.
97
94
 
98
95
  ```js
99
- import { createWorkerHandler } from 'worker-pool';
96
+ import { createWorkerHandler } from 'node-worker-pool-lite';
100
97
 
101
98
  createWorkerHandler({
102
99
  resizeImage(payload) {
@@ -157,7 +154,7 @@ pool.run('refreshCache', error => {
157
154
  });
158
155
  ```
159
156
 
160
- ### `pool.run(name, payload)` from `worker-pool/promise`
157
+ ### `pool.run(name, payload)` from `node-worker-pool-lite/promise`
161
158
 
162
159
  Queues a named task and returns a promise.
163
160
 
@@ -208,16 +205,19 @@ Preview the package contents before publishing:
208
205
  npm pack --dry-run
209
206
  ```
210
207
 
211
- ## Publishing Notes
208
+ ## Repository
209
+
210
+ - GitHub: [armanmikoyan/node-worker-pool](https://github.com/armanmikoyan/node-worker-pool)
211
+ - npm: [node-worker-pool-lite](https://www.npmjs.com/package/node-worker-pool-lite)
212
+
213
+ ## Release Checklist
212
214
 
213
- Before publishing to npm:
215
+ Before publishing a new npm version:
214
216
 
215
- - Choose a unique package name and update `package.json`.
216
- - Add `author`, `repository`, `homepage`, and `bugs` fields to `package.json`.
217
- - Update `LICENSE` with your name.
218
217
  - Run `npm test` and `npm pack --dry-run`.
219
- - Publish scoped public packages with `npm publish --access public`.
218
+ - Update the version with `npm version patch`, `npm version minor`, or `npm version major`.
219
+ - Publish with `npm publish`.
220
220
 
221
221
  ## License
222
222
 
223
- MIT
223
+ MIT © [Arman Mikoyan](https://github.com/armanmikoyan)
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "node-worker-pool-lite",
3
3
  "author": "Arman Mikoyan <arman@mikoyan1@gmail.com>",
4
- "version": "0.1.0",
5
- "description": "A lightweight callback and promise worker_threads pool for Node.js.",
4
+ "version": "0.1.2",
5
+ "description": "A lightweight Node.js worker_threads pool with callback and Promise APIs.",
6
6
  "type": "module",
7
7
  "main": "./lib/index.js",
8
8
  "types": "./lib/index.d.ts",
@@ -18,24 +18,42 @@
18
18
  },
19
19
  "files": [
20
20
  "lib",
21
- "examples",
22
21
  "README.md",
23
22
  "LICENSE"
24
23
  ],
25
24
  "scripts": {
26
25
  "test": "node --test test/*.test.js"
27
26
  },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/armanmikoyan/node-worker-pool.git"
30
+ },
31
+ "homepage": "https://github.com/armanmikoyan/node-worker-pool#readme",
32
+ "bugs": {
33
+ "url": "https://github.com/armanmikoyan/node-worker-pool/issues"
34
+ },
28
35
  "keywords": [
36
+ "node",
37
+ "nodejs",
29
38
  "worker_threads",
30
39
  "worker-pool",
40
+ "worker-thread-pool",
31
41
  "thread-pool",
32
42
  "concurrency",
43
+ "parallel",
44
+ "parallel-processing",
33
45
  "pool",
34
46
  "parallelism",
35
- "cpu-intensive"
47
+ "cpu-intensive",
48
+ "cpu-bound",
49
+ "background-jobs",
50
+ "task-queue",
51
+ "esm",
52
+ "typescript"
36
53
  ],
37
54
  "engines": {
38
55
  "node": ">=18"
39
56
  },
57
+ "sideEffects": false,
40
58
  "license": "MIT"
41
59
  }
package/examples/basic.js DELETED
@@ -1,24 +0,0 @@
1
- import { WorkerPool } from '../lib/index.js';
2
-
3
- const pool = new WorkerPool(new URL('./prime-worker.js', import.meta.url), {
4
- size: 3,
5
- });
6
-
7
- let pendingTasks = 2;
8
-
9
- pool.run('primes', { count: 10 }, handleResult);
10
- pool.run('primes', { count: 20 }, handleResult);
11
-
12
- async function handleResult(error, primes) {
13
- pendingTasks -= 1;
14
-
15
- if (error) {
16
- console.error(error);
17
- } else {
18
- console.log(primes);
19
- }
20
-
21
- if (pendingTasks === 0) {
22
- await pool.destroy();
23
- }
24
- }
@@ -1,36 +0,0 @@
1
- import { createWorkerHandler } from '../lib/index.js';
2
-
3
- createWorkerHandler({
4
- primes({ count = 1 } = {}) {
5
- return generatePrimes(count);
6
- },
7
- });
8
-
9
- function generatePrimes(count) {
10
- const primes = [];
11
- let candidate = 2;
12
-
13
- while (primes.length < count) {
14
- if (isPrime(candidate)) {
15
- primes.push(candidate);
16
- }
17
-
18
- candidate += 1;
19
- }
20
-
21
- return primes;
22
- }
23
-
24
- function isPrime(value) {
25
- if (value < 2) {
26
- return false;
27
- }
28
-
29
- for (let divisor = 2; divisor * divisor <= value; divisor += 1) {
30
- if (value % divisor === 0) {
31
- return false;
32
- }
33
- }
34
-
35
- return true;
36
- }
@@ -1,17 +0,0 @@
1
- import { WorkerPool } from '../lib/promise.js';
2
-
3
- const pool = new WorkerPool(new URL('./prime-worker.js', import.meta.url), {
4
- size: 3,
5
- });
6
-
7
- try {
8
- const [firstBatch, secondBatch] = await Promise.all([
9
- pool.run('primes', { count: 10 }),
10
- pool.run('primes', { count: 20 }),
11
- ]);
12
-
13
- console.log(firstBatch);
14
- console.log(secondBatch);
15
- } finally {
16
- await pool.destroy();
17
- }