nestworker 1.1.21 → 2.0.8

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 (63) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +307 -143
  3. package/dist/core/worker.interfaces.d.ts +36 -0
  4. package/dist/{models/task.js → core/worker.interfaces.js} +1 -1
  5. package/dist/core/worker.interfaces.js.map +1 -0
  6. package/dist/core/worker.module.d.ts +15 -0
  7. package/dist/core/worker.module.js +43 -0
  8. package/dist/core/worker.module.js.map +1 -0
  9. package/dist/core/worker.pool.d.ts +20 -0
  10. package/dist/core/worker.pool.js +210 -0
  11. package/dist/core/worker.pool.js.map +1 -0
  12. package/dist/core/worker.service.d.ts +88 -0
  13. package/dist/core/worker.service.js +135 -0
  14. package/dist/core/worker.service.js.map +1 -0
  15. package/dist/decorators/worker-task.decorator.d.ts +37 -0
  16. package/dist/decorators/worker-task.decorator.js +48 -0
  17. package/dist/decorators/worker-task.decorator.js.map +1 -0
  18. package/dist/di/di-serializer.d.ts +19 -0
  19. package/dist/di/di-serializer.js +133 -0
  20. package/dist/di/di-serializer.js.map +1 -0
  21. package/dist/di/worker-container.d.ts +60 -0
  22. package/dist/di/worker-container.js +170 -0
  23. package/dist/di/worker-container.js.map +1 -0
  24. package/dist/discovery/discovery.service.d.ts +20 -0
  25. package/dist/discovery/discovery.service.js +94 -0
  26. package/dist/discovery/discovery.service.js.map +1 -0
  27. package/dist/example/config.service.d.ts +13 -0
  28. package/dist/example/config.service.js +35 -0
  29. package/dist/example/config.service.js.map +1 -0
  30. package/dist/example/image.service.d.ts +13 -0
  31. package/dist/example/image.service.js +123 -0
  32. package/dist/example/image.service.js.map +1 -0
  33. package/dist/example/main.d.ts +1 -0
  34. package/dist/example/main.js +60 -0
  35. package/dist/example/main.js.map +1 -0
  36. package/dist/index.d.ts +5 -0
  37. package/dist/index.js +11 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/worker/worker-runtime.js +55 -0
  40. package/dist/worker/worker-runtime.js.map +1 -0
  41. package/package.json +58 -55
  42. package/CONTRIBUTING.md +0 -33
  43. package/dist/main.d.ts +0 -3
  44. package/dist/main.js +0 -29
  45. package/dist/main.js.map +0 -1
  46. package/dist/models/index.d.ts +0 -1
  47. package/dist/models/index.js +0 -18
  48. package/dist/models/index.js.map +0 -1
  49. package/dist/models/task.d.ts +0 -5
  50. package/dist/models/task.js.map +0 -1
  51. package/dist/tsconfig.build.tsbuildinfo +0 -1
  52. package/dist/worker/executor.d.ts +0 -5
  53. package/dist/worker/executor.js +0 -28
  54. package/dist/worker/executor.js.map +0 -1
  55. package/dist/worker/skeleton.d.ts +0 -6
  56. package/dist/worker/skeleton.js +0 -35
  57. package/dist/worker/skeleton.js.map +0 -1
  58. package/dist/worker/worker.js +0 -6
  59. package/dist/worker/worker.js.map +0 -1
  60. package/nest-cli.json +0 -8
  61. package/tsconfig.build.json +0 -4
  62. package/tsconfig.json +0 -25
  63. /package/dist/worker/{worker.d.ts → worker-runtime.d.ts} +0 -0
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startWorker = void 0;
4
- const path = require("node:path");
5
- const node_worker_threads_1 = require("node:worker_threads");
6
- const workerPath = path.join(__dirname, 'worker.js');
7
- const startWorker = (workerData) => new Promise((resolve, reject) => {
8
- const worker = new node_worker_threads_1.Worker(workerPath, {
9
- workerData,
10
- });
11
- let finished = false;
12
- worker.once('message', ({ errMessage, data }) => {
13
- finished = true;
14
- if (errMessage)
15
- reject(new Error(`Thread ${errMessage}`));
16
- else
17
- resolve(data);
18
- });
19
- worker.once('error', reject);
20
- worker.once('exit', () => {
21
- if (!finished) {
22
- finished = true;
23
- resolve();
24
- }
25
- });
26
- });
27
- exports.startWorker = startWorker;
28
- //# sourceMappingURL=executor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/worker/executor.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAClC,6DAA6C;AAE7C,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAO9C,MAAM,WAAW,GAAG,CAAI,UAI9B,EAAgB,EAAE,CACjB,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IACpC,MAAM,MAAM,GAAG,IAAI,4BAAM,CAAC,UAAU,EAAE;QACpC,UAAU;KACX,CAAC,CAAC;IAEH,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE;QAC9C,QAAQ,GAAG,IAAI,CAAC;QAEhB,IAAI,UAAU;YAAE,MAAM,CAAC,IAAI,KAAK,CAAC,UAAU,UAAU,EAAE,CAAC,CAAC,CAAC;;YACrD,OAAO,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAE7B,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE;QACvB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,GAAG,IAAI,CAAC;YAChB,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AA3BQ,QAAA,WAAW,eA2BnB"}
@@ -1,6 +0,0 @@
1
- import { TaskFunction } from '../models';
2
- export declare const createWorker: <T, P>(task: TaskFunction<T>, params: P[], modules: string[]) => {
3
- workerCode: string;
4
- workerParams: P[];
5
- workerModules: string[];
6
- };
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createWorker = void 0;
4
- const generateWorkerCode = (func) => `
5
- (async () => {
6
- const { parentPort, workerData } = await import('worker_threads');
7
-
8
- async function loadModules(moduleNames) {
9
- const modules = {};
10
- for (const moduleName of moduleNames) {
11
- modules[moduleName] = await import(moduleName);
12
- }
13
- return modules;
14
- }
15
-
16
- try {
17
- const task = ${func};
18
- const res = workerData.workerModules.length > 0
19
- ? task(await loadModules(workerData.workerModules), ...workerData.workerParams)
20
- : task(...workerData.workerParams);
21
-
22
- const data = (res instanceof Promise) ? await res : res;
23
- parentPort.postMessage({ data });
24
- } catch(err) {
25
- parentPort.postMessage({ errMessage: err.toString() });
26
- }
27
- })();
28
- `;
29
- const createWorker = (task, params, modules) => ({
30
- workerCode: generateWorkerCode(task.toString()),
31
- workerParams: params,
32
- workerModules: modules,
33
- });
34
- exports.createWorker = createWorker;
35
- //# sourceMappingURL=skeleton.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"skeleton.js","sourceRoot":"","sources":["../../src/worker/skeleton.ts"],"names":[],"mappings":";;;AAOA,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC;;;;;;;;;;;;;qBAahC,IAAI;;;;;;;;;;;CAWxB,CAAC;AASK,MAAM,YAAY,GAAG,CAC1B,IAAqB,EACrB,MAAW,EACX,OAAiB,EACjB,EAAE,CAAC,CAAC;IACJ,UAAU,EAAE,kBAAkB,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC/C,YAAY,EAAE,MAAM;IACpB,aAAa,EAAE,OAAO;CACvB,CAAC,CAAC;AARU,QAAA,YAAY,gBAQtB"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_worker_threads_1 = require("node:worker_threads");
4
- const { workerCode } = node_worker_threads_1.workerData;
5
- eval(workerCode);
6
- //# sourceMappingURL=worker.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/worker/worker.ts"],"names":[],"mappings":";;AAAA,6DAAiD;AAEjD,MAAM,EAAE,UAAU,EAAE,GAAG,gCAAU,CAAC;AAMlC,IAAI,CAAC,UAAU,CAAC,CAAC"}
package/nest-cli.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/nest-cli",
3
- "collection": "@nestjs/schematics",
4
- "sourceRoot": "src",
5
- "compilerOptions": {
6
- "deleteOutDir": true
7
- }
8
- }
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": ["node_modules", "test", "dist", "**/*spec.ts", "examples"]
4
- }
package/tsconfig.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "declaration": true,
5
- "removeComments": true,
6
- "emitDecoratorMetadata": true,
7
- "experimentalDecorators": true,
8
- "allowSyntheticDefaultImports": true,
9
- "target": "ES2021",
10
- "sourceMap": true,
11
- "outDir": "./dist",
12
- "baseUrl": "./",
13
- "incremental": true,
14
- "skipLibCheck": true,
15
- "strictNullChecks": false,
16
- "noImplicitAny": false,
17
- "strictBindCallApply": false,
18
- "forceConsistentCasingInFileNames": false,
19
- "noFallthroughCasesInSwitch": false
20
- },
21
- "exclude": [
22
- "node_modules",
23
- "dist"
24
- ],
25
- }