node-worker-pool-lite 0.1.0 → 0.1.1
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 +23 -23
- package/package.json +22 -3
package/README.md
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
# Worker Pool
|
|
1
|
+
# Node Worker Pool Lite
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/node-worker-pool-lite)
|
|
4
|
+
[](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
|
-
##
|
|
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
|
|
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
|
-
-
|
|
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.
|
|
5
|
-
"description": "A lightweight
|
|
4
|
+
"version": "0.1.1",
|
|
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",
|
|
@@ -25,17 +25,36 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"test": "node --test test/*.test.js"
|
|
27
27
|
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/armanmikoyan/node-worker-pool.git"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/armanmikoyan/node-worker-pool#readme",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/armanmikoyan/node-worker-pool/issues"
|
|
35
|
+
},
|
|
28
36
|
"keywords": [
|
|
37
|
+
"node",
|
|
38
|
+
"nodejs",
|
|
29
39
|
"worker_threads",
|
|
30
40
|
"worker-pool",
|
|
41
|
+
"worker-thread-pool",
|
|
31
42
|
"thread-pool",
|
|
32
43
|
"concurrency",
|
|
44
|
+
"parallel",
|
|
45
|
+
"parallel-processing",
|
|
33
46
|
"pool",
|
|
34
47
|
"parallelism",
|
|
35
|
-
"cpu-intensive"
|
|
48
|
+
"cpu-intensive",
|
|
49
|
+
"cpu-bound",
|
|
50
|
+
"background-jobs",
|
|
51
|
+
"task-queue",
|
|
52
|
+
"esm",
|
|
53
|
+
"typescript"
|
|
36
54
|
],
|
|
37
55
|
"engines": {
|
|
38
56
|
"node": ">=18"
|
|
39
57
|
},
|
|
58
|
+
"sideEffects": false,
|
|
40
59
|
"license": "MIT"
|
|
41
60
|
}
|