node-worker-pool-lite 0.1.1 → 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-worker-pool-lite",
3
3
  "author": "Arman Mikoyan <arman@mikoyan1@gmail.com>",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "description": "A lightweight Node.js worker_threads pool with callback and Promise APIs.",
6
6
  "type": "module",
7
7
  "main": "./lib/index.js",
@@ -18,7 +18,6 @@
18
18
  },
19
19
  "files": [
20
20
  "lib",
21
- "examples",
22
21
  "README.md",
23
22
  "LICENSE"
24
23
  ],
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
- }