vivth 1.1.0 → 1.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 +43 -23
- package/dev/index.mjs +3 -3
- package/package.json +1 -1
- package/src/class/Paths.mjs +12 -3
- package/src/class/SafeExit.mjs +18 -18
- package/src/class/Setup.mjs +8 -6
- package/src/class/WorkerMainThread.mjs +10 -4
- package/src/class/WorkerThread.mjs +5 -2
- package/types/src/class/Paths.d.mts +12 -3
- package/types/src/class/SafeExit.d.mts +13 -13
- package/types/src/class/Setup.d.mts +8 -6
- package/types/src/class/WorkerMainThread.d.mts +10 -4
- package/types/src/class/WorkerThread.d.mts +5 -2
package/README.md
CHANGED
|
@@ -846,9 +846,18 @@ npm i vivth
|
|
|
846
846
|
/**
|
|
847
847
|
* @param {Object} options
|
|
848
848
|
* @param {string} options.root
|
|
849
|
-
* - browser:
|
|
850
|
-
*
|
|
851
|
-
*
|
|
849
|
+
* - browser:
|
|
850
|
+
* ```js
|
|
851
|
+
* location.origin
|
|
852
|
+
* ```
|
|
853
|
+
* - node/bun compatible:
|
|
854
|
+
* ```js
|
|
855
|
+
* process?.env?.INIT_CWD ?? process?.cwd()
|
|
856
|
+
* ```
|
|
857
|
+
* - deno: need for `deno run --allow-env --allow-read your_script.ts`:
|
|
858
|
+
* ```js
|
|
859
|
+
* Deno.env.get("INIT_CWD") ?? Deno.cwd()
|
|
860
|
+
* ```
|
|
852
861
|
* - other: you need to check your JSRuntime for the rootPath reference;
|
|
853
862
|
*/
|
|
854
863
|
```
|
|
@@ -1031,7 +1040,7 @@ npm i vivth
|
|
|
1031
1040
|
|
|
1032
1041
|
```js
|
|
1033
1042
|
/**
|
|
1034
|
-
* @template {[string, ...string[]]}
|
|
1043
|
+
* @template {[string, ...string[]]} eventNames
|
|
1035
1044
|
*/
|
|
1036
1045
|
```
|
|
1037
1046
|
|
|
@@ -1050,8 +1059,8 @@ npm i vivth
|
|
|
1050
1059
|
```js
|
|
1051
1060
|
/**
|
|
1052
1061
|
* @param {Object} options
|
|
1053
|
-
* @param {
|
|
1054
|
-
* @param {()=>void} options.
|
|
1062
|
+
* @param {eventNames} options.eventNames
|
|
1063
|
+
* @param {()=>void} options.terminator
|
|
1055
1064
|
* - standard node/bun:
|
|
1056
1065
|
* ```js
|
|
1057
1066
|
* () => process.exit(0),
|
|
@@ -1060,7 +1069,7 @@ npm i vivth
|
|
|
1060
1069
|
* ```js
|
|
1061
1070
|
* () => Deno.exit(0),
|
|
1062
1071
|
* ```
|
|
1063
|
-
* @param {(eventName:string)=>void} [options.
|
|
1072
|
+
* @param {(eventName:string)=>void} [options.listener]
|
|
1064
1073
|
* - default value
|
|
1065
1074
|
* ```js
|
|
1066
1075
|
* (eventName) => {
|
|
@@ -1078,12 +1087,12 @@ npm i vivth
|
|
|
1078
1087
|
import { SafeExit, Console } from 'vivth';
|
|
1079
1088
|
|
|
1080
1089
|
new SafeExit({
|
|
1081
|
-
//
|
|
1090
|
+
// eventNames are blank by default, you need to manually name them all;
|
|
1082
1091
|
// 'exit' will be omited, as it might cause async callbacks failed to execute;
|
|
1083
|
-
|
|
1084
|
-
|
|
1092
|
+
eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
|
|
1093
|
+
terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
|
|
1085
1094
|
// optional deno example
|
|
1086
|
-
|
|
1095
|
+
listener = (eventName) => {
|
|
1087
1096
|
const sig = Deno.signal(eventName);
|
|
1088
1097
|
for await (const _ of sig) {
|
|
1089
1098
|
exiting.correction(true);
|
|
@@ -1142,15 +1151,17 @@ npm i vivth
|
|
|
1142
1151
|
import { Setup, Console } from 'vivth';
|
|
1143
1152
|
|
|
1144
1153
|
new Setup.safeExit({
|
|
1145
|
-
//
|
|
1146
|
-
|
|
1154
|
+
// eventNames are blank by default, you need to manually name them all;
|
|
1155
|
+
// 'exit' will be omited, as it might cause async callbacks failed to execute;
|
|
1156
|
+
eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
|
|
1157
|
+
terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
|
|
1147
1158
|
// optional deno example
|
|
1148
|
-
|
|
1159
|
+
listener = (eventName) => {
|
|
1149
1160
|
const sig = Deno.signal(eventName);
|
|
1150
1161
|
for await (const _ of sig) {
|
|
1151
|
-
|
|
1162
|
+
exiting.correction(true);
|
|
1152
1163
|
sig.dispose();
|
|
1153
|
-
Console.
|
|
1164
|
+
Console.log(`safe exit via "${eventName}"`);
|
|
1154
1165
|
}
|
|
1155
1166
|
}
|
|
1156
1167
|
});
|
|
@@ -1199,7 +1210,7 @@ npm i vivth
|
|
|
1199
1210
|
```js
|
|
1200
1211
|
import { Setup } from 'vivth';
|
|
1201
1212
|
|
|
1202
|
-
Setup.workerThread({ parentPort: async () => await import('node:worker_threads') });
|
|
1213
|
+
Setup.workerThread({ parentPort: async () => (await import('node:worker_threads')).parentPort });
|
|
1203
1214
|
// that is the default value, if your parentPort/equivalent API is not that;
|
|
1204
1215
|
// you need to call this method;
|
|
1205
1216
|
|
|
@@ -1380,12 +1391,18 @@ npm i vivth
|
|
|
1380
1391
|
/**
|
|
1381
1392
|
* @param {Object} param0
|
|
1382
1393
|
* @param {typeof WorkerMainThread["workerClass"]} param0.workerClass
|
|
1394
|
+
* - example:
|
|
1395
|
+
* ```js
|
|
1396
|
+
* async () => await (import('worker_threads')).Worker
|
|
1397
|
+
* ```
|
|
1383
1398
|
* @param {typeof WorkerMainThread["pathValidator"]} param0.pathValidator
|
|
1399
|
+
* - example:
|
|
1384
1400
|
* ```js
|
|
1385
|
-
*
|
|
1386
|
-
*
|
|
1387
|
-
*
|
|
1388
|
-
*
|
|
1401
|
+
* async (workerPath, root, base) => {
|
|
1402
|
+
* const res = await fetch(`${root}/${base}/${workerPath}`);
|
|
1403
|
+
* // might also check wheter it need base or not
|
|
1404
|
+
* return await res.ok;
|
|
1405
|
+
* }
|
|
1389
1406
|
* ```
|
|
1390
1407
|
* @param {typeof WorkerMainThread["basePath"]} [param0.basePath]
|
|
1391
1408
|
* - additonal realtivePath from rootPath;
|
|
@@ -1573,7 +1590,10 @@ npm i vivth
|
|
|
1573
1590
|
* @template Receive_
|
|
1574
1591
|
* @template Post_
|
|
1575
1592
|
* @param {{parentPort:()=>Promise<any>}} parentPortRef
|
|
1576
|
-
* - correct parentPort reference
|
|
1593
|
+
* - correct parentPort reference, example:
|
|
1594
|
+
* ```js
|
|
1595
|
+
* async () => (await import('node:worker_threads')).parentPort
|
|
1596
|
+
* ```
|
|
1577
1597
|
* @returns {typeof WorkerThread<Receive_, Post_>}
|
|
1578
1598
|
*/
|
|
1579
1599
|
```
|
|
@@ -1581,7 +1601,7 @@ npm i vivth
|
|
|
1581
1601
|
```js
|
|
1582
1602
|
import { WorkerThread } from 'vivth';
|
|
1583
1603
|
|
|
1584
|
-
WorkerThread.setup({ parentPort: async () => await import('node:worker_threads') });
|
|
1604
|
+
WorkerThread.setup({ parentPort: async () => (await import('node:worker_threads')).parentPort });
|
|
1585
1605
|
// that is the default value, if your parentPort/equivalent API is not that;
|
|
1586
1606
|
// you need to call this method;
|
|
1587
1607
|
|
package/dev/index.mjs
CHANGED
|
@@ -11,9 +11,9 @@ new paths({
|
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
new safeExit({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
eventNames: ['SIGINT', 'SIGTERM', 'exit'],
|
|
15
|
+
terminator: () => process.exit(0),
|
|
16
|
+
listener: (eventName) => {
|
|
17
17
|
process.once(eventName, function () {
|
|
18
18
|
safeExit.instance.exiting.correction(true);
|
|
19
19
|
Console.log(`safe exit via "${eventName}"`);
|
package/package.json
CHANGED
package/src/class/Paths.mjs
CHANGED
|
@@ -16,9 +16,18 @@ export class Paths {
|
|
|
16
16
|
* @description
|
|
17
17
|
* @param {Object} options
|
|
18
18
|
* @param {string} options.root
|
|
19
|
-
* - browser:
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* - browser:
|
|
20
|
+
* ```js
|
|
21
|
+
* location.origin
|
|
22
|
+
* ```
|
|
23
|
+
* - node/bun compatible:
|
|
24
|
+
* ```js
|
|
25
|
+
* process?.env?.INIT_CWD ?? process?.cwd()
|
|
26
|
+
* ```
|
|
27
|
+
* - deno: need for `deno run --allow-env --allow-read your_script.ts`:
|
|
28
|
+
* ```js
|
|
29
|
+
* Deno.env.get("INIT_CWD") ?? Deno.cwd()
|
|
30
|
+
* ```
|
|
22
31
|
* - other: you need to check your JSRuntime for the rootPath reference;
|
|
23
32
|
* @example
|
|
24
33
|
* import { Paths } from 'vivth';
|
package/src/class/SafeExit.mjs
CHANGED
|
@@ -15,7 +15,7 @@ export const safeCleanUpCBs = new Set();
|
|
|
15
15
|
* @description
|
|
16
16
|
* - class helper for describing how to Safely Response on exit events
|
|
17
17
|
* - singleton;
|
|
18
|
-
* @template {[string, ...string[]]}
|
|
18
|
+
* @template {[string, ...string[]]} eventNames
|
|
19
19
|
*/
|
|
20
20
|
export class SafeExit {
|
|
21
21
|
/**
|
|
@@ -27,8 +27,8 @@ export class SafeExit {
|
|
|
27
27
|
/**
|
|
28
28
|
* @description
|
|
29
29
|
* @param {Object} options
|
|
30
|
-
* @param {
|
|
31
|
-
* @param {()=>void} options.
|
|
30
|
+
* @param {eventNames} options.eventNames
|
|
31
|
+
* @param {()=>void} options.terminator
|
|
32
32
|
* - standard node/bun:
|
|
33
33
|
* ```js
|
|
34
34
|
* () => process.exit(0),
|
|
@@ -37,7 +37,7 @@ export class SafeExit {
|
|
|
37
37
|
* ```js
|
|
38
38
|
* () => Deno.exit(0),
|
|
39
39
|
* ```
|
|
40
|
-
* @param {(eventName:string)=>void} [options.
|
|
40
|
+
* @param {(eventName:string)=>void} [options.listener]
|
|
41
41
|
* - default value
|
|
42
42
|
* ```js
|
|
43
43
|
* (eventName) => {
|
|
@@ -52,12 +52,12 @@ export class SafeExit {
|
|
|
52
52
|
* import { SafeExit, Console } from 'vivth';
|
|
53
53
|
*
|
|
54
54
|
* new SafeExit({
|
|
55
|
-
* //
|
|
55
|
+
* // eventNames are blank by default, you need to manually name them all;
|
|
56
56
|
* // 'exit' will be omited, as it might cause async callbacks failed to execute;
|
|
57
|
-
*
|
|
58
|
-
*
|
|
57
|
+
* eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
|
|
58
|
+
* terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
|
|
59
59
|
* // optional deno example
|
|
60
|
-
*
|
|
60
|
+
* listener = (eventName) => {
|
|
61
61
|
* const sig = Deno.signal(eventName);
|
|
62
62
|
* for await (const _ of sig) {
|
|
63
63
|
* exiting.correction(true);
|
|
@@ -67,16 +67,16 @@ export class SafeExit {
|
|
|
67
67
|
* }
|
|
68
68
|
* });
|
|
69
69
|
*/
|
|
70
|
-
constructor({
|
|
70
|
+
constructor({ eventNames, terminator, listener = undefined }) {
|
|
71
71
|
if (SafeExit.instance) {
|
|
72
72
|
return SafeExit.instance;
|
|
73
73
|
}
|
|
74
74
|
SafeExit.instance = this;
|
|
75
|
-
this.#exit =
|
|
76
|
-
if (
|
|
77
|
-
this.#
|
|
75
|
+
this.#exit = terminator;
|
|
76
|
+
if (listener) {
|
|
77
|
+
this.#listener = listener;
|
|
78
78
|
}
|
|
79
|
-
this.#register(
|
|
79
|
+
this.#register(eventNames);
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* @description
|
|
@@ -86,21 +86,21 @@ export class SafeExit {
|
|
|
86
86
|
*/
|
|
87
87
|
exiting = new EnvSignal(false);
|
|
88
88
|
/**
|
|
89
|
-
* @param {
|
|
89
|
+
* @param {eventNames} eventNames
|
|
90
90
|
* @returns {void}
|
|
91
91
|
*/
|
|
92
|
-
#register = (
|
|
93
|
-
|
|
92
|
+
#register = (eventNames) => {
|
|
93
|
+
eventNames.forEach((eventName) => {
|
|
94
94
|
if (eventName == 'exit') {
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
-
this.#
|
|
97
|
+
this.#listener(eventName);
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
100
|
/**
|
|
101
101
|
* @type {(eventName:string)=>void}
|
|
102
102
|
*/
|
|
103
|
-
#
|
|
103
|
+
#listener = (eventName) => {
|
|
104
104
|
SafeExit.instance.exiting.env.value;
|
|
105
105
|
process.once(eventName, function () {
|
|
106
106
|
Console.log(`safe exit via "${eventName}"`);
|
package/src/class/Setup.mjs
CHANGED
|
@@ -17,15 +17,17 @@ export class Setup {
|
|
|
17
17
|
* import { Setup, Console } from 'vivth';
|
|
18
18
|
*
|
|
19
19
|
* new Setup.safeExit({
|
|
20
|
-
* //
|
|
21
|
-
*
|
|
20
|
+
* // eventNames are blank by default, you need to manually name them all;
|
|
21
|
+
* // 'exit' will be omited, as it might cause async callbacks failed to execute;
|
|
22
|
+
* eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
|
|
23
|
+
* terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
|
|
22
24
|
* // optional deno example
|
|
23
|
-
*
|
|
25
|
+
* listener = (eventName) => {
|
|
24
26
|
* const sig = Deno.signal(eventName);
|
|
25
27
|
* for await (const _ of sig) {
|
|
26
|
-
*
|
|
28
|
+
* exiting.correction(true);
|
|
27
29
|
* sig.dispose();
|
|
28
|
-
* Console.
|
|
30
|
+
* Console.log(`safe exit via "${eventName}"`);
|
|
29
31
|
* }
|
|
30
32
|
* }
|
|
31
33
|
* });
|
|
@@ -65,7 +67,7 @@ export class Setup {
|
|
|
65
67
|
* @example
|
|
66
68
|
* import { Setup } from 'vivth';
|
|
67
69
|
*
|
|
68
|
-
* Setup.workerThread({ parentPort: async () => await import('node:worker_threads') });
|
|
70
|
+
* Setup.workerThread({ parentPort: async () => (await import('node:worker_threads')).parentPort });
|
|
69
71
|
* // that is the default value, if your parentPort/equivalent API is not that;
|
|
70
72
|
* // you need to call this method;
|
|
71
73
|
*/
|
|
@@ -31,12 +31,18 @@ export class WorkerMainThread {
|
|
|
31
31
|
* - need to be called first, before any `WorkerMainThread` instantiation:
|
|
32
32
|
* @param {Object} param0
|
|
33
33
|
* @param {typeof WorkerMainThread["workerClass"]} param0.workerClass
|
|
34
|
+
* - example:
|
|
35
|
+
* ```js
|
|
36
|
+
* async () => await (import('worker_threads')).Worker
|
|
37
|
+
* ```
|
|
34
38
|
* @param {typeof WorkerMainThread["pathValidator"]} param0.pathValidator
|
|
39
|
+
* - example:
|
|
35
40
|
* ```js
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
41
|
+
* async (workerPath, root, base) => {
|
|
42
|
+
* const res = await fetch(`${root}/${base}/${workerPath}`);
|
|
43
|
+
* // might also check wheter it need base or not
|
|
44
|
+
* return await res.ok;
|
|
45
|
+
* }
|
|
40
46
|
* ```
|
|
41
47
|
* @param {typeof WorkerMainThread["basePath"]} [param0.basePath]
|
|
42
48
|
* - additonal realtivePath from rootPath;
|
|
@@ -28,12 +28,15 @@ export class WorkerThread {
|
|
|
28
28
|
* @template Receive_
|
|
29
29
|
* @template Post_
|
|
30
30
|
* @param {{parentPort:()=>Promise<any>}} parentPortRef
|
|
31
|
-
* - correct parentPort reference
|
|
31
|
+
* - correct parentPort reference, example:
|
|
32
|
+
* ```js
|
|
33
|
+
* async () => (await import('node:worker_threads')).parentPort
|
|
34
|
+
* ```
|
|
32
35
|
* @returns {typeof WorkerThread<Receive_, Post_>}
|
|
33
36
|
* @example
|
|
34
37
|
* import { WorkerThread } from 'vivth';
|
|
35
38
|
*
|
|
36
|
-
* WorkerThread.setup({ parentPort: async () => await import('node:worker_threads') });
|
|
39
|
+
* WorkerThread.setup({ parentPort: async () => (await import('node:worker_threads')).parentPort });
|
|
37
40
|
* // that is the default value, if your parentPort/equivalent API is not that;
|
|
38
41
|
* // you need to call this method;
|
|
39
42
|
*/
|
|
@@ -32,9 +32,18 @@ export class Paths {
|
|
|
32
32
|
* @description
|
|
33
33
|
* @param {Object} options
|
|
34
34
|
* @param {string} options.root
|
|
35
|
-
* - browser:
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* - browser:
|
|
36
|
+
* ```js
|
|
37
|
+
* location.origin
|
|
38
|
+
* ```
|
|
39
|
+
* - node/bun compatible:
|
|
40
|
+
* ```js
|
|
41
|
+
* process?.env?.INIT_CWD ?? process?.cwd()
|
|
42
|
+
* ```
|
|
43
|
+
* - deno: need for `deno run --allow-env --allow-read your_script.ts`:
|
|
44
|
+
* ```js
|
|
45
|
+
* Deno.env.get("INIT_CWD") ?? Deno.cwd()
|
|
46
|
+
* ```
|
|
38
47
|
* - other: you need to check your JSRuntime for the rootPath reference;
|
|
39
48
|
* @example
|
|
40
49
|
* import { Paths } from 'vivth';
|
|
@@ -6,9 +6,9 @@ export const safeCleanUpCBs: Set<() => Promise<void>>;
|
|
|
6
6
|
* @description
|
|
7
7
|
* - class helper for describing how to Safely Response on exit events
|
|
8
8
|
* - singleton;
|
|
9
|
-
* @template {[string, ...string[]]}
|
|
9
|
+
* @template {[string, ...string[]]} eventNames
|
|
10
10
|
*/
|
|
11
|
-
export class SafeExit<
|
|
11
|
+
export class SafeExit<eventNames extends [string, ...string[]]> {
|
|
12
12
|
/**
|
|
13
13
|
* @description
|
|
14
14
|
* - only accessible after instantiation;
|
|
@@ -18,8 +18,8 @@ export class SafeExit<ExitEventNames extends [string, ...string[]]> {
|
|
|
18
18
|
/**
|
|
19
19
|
* @description
|
|
20
20
|
* @param {Object} options
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {()=>void} options.
|
|
21
|
+
* @param {eventNames} options.eventNames
|
|
22
|
+
* @param {()=>void} options.terminator
|
|
23
23
|
* - standard node/bun:
|
|
24
24
|
* ```js
|
|
25
25
|
* () => process.exit(0),
|
|
@@ -28,7 +28,7 @@ export class SafeExit<ExitEventNames extends [string, ...string[]]> {
|
|
|
28
28
|
* ```js
|
|
29
29
|
* () => Deno.exit(0),
|
|
30
30
|
* ```
|
|
31
|
-
* @param {(eventName:string)=>void} [options.
|
|
31
|
+
* @param {(eventName:string)=>void} [options.listener]
|
|
32
32
|
* - default value
|
|
33
33
|
* ```js
|
|
34
34
|
* (eventName) => {
|
|
@@ -43,12 +43,12 @@ export class SafeExit<ExitEventNames extends [string, ...string[]]> {
|
|
|
43
43
|
* import { SafeExit, Console } from 'vivth';
|
|
44
44
|
*
|
|
45
45
|
* new SafeExit({
|
|
46
|
-
* //
|
|
46
|
+
* // eventNames are blank by default, you need to manually name them all;
|
|
47
47
|
* // 'exit' will be omited, as it might cause async callbacks failed to execute;
|
|
48
|
-
*
|
|
49
|
-
*
|
|
48
|
+
* eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
|
|
49
|
+
* terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
|
|
50
50
|
* // optional deno example
|
|
51
|
-
*
|
|
51
|
+
* listener = (eventName) => {
|
|
52
52
|
* const sig = Deno.signal(eventName);
|
|
53
53
|
* for await (const _ of sig) {
|
|
54
54
|
* exiting.correction(true);
|
|
@@ -58,10 +58,10 @@ export class SafeExit<ExitEventNames extends [string, ...string[]]> {
|
|
|
58
58
|
* }
|
|
59
59
|
* });
|
|
60
60
|
*/
|
|
61
|
-
constructor({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
constructor({ eventNames, terminator, listener }: {
|
|
62
|
+
eventNames: eventNames;
|
|
63
|
+
terminator: () => void;
|
|
64
|
+
listener?: (eventName: string) => void;
|
|
65
65
|
});
|
|
66
66
|
/**
|
|
67
67
|
* @description
|
|
@@ -10,15 +10,17 @@ export class Setup {
|
|
|
10
10
|
* import { Setup, Console } from 'vivth';
|
|
11
11
|
*
|
|
12
12
|
* new Setup.safeExit({
|
|
13
|
-
* //
|
|
14
|
-
*
|
|
13
|
+
* // eventNames are blank by default, you need to manually name them all;
|
|
14
|
+
* // 'exit' will be omited, as it might cause async callbacks failed to execute;
|
|
15
|
+
* eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
|
|
16
|
+
* terminator = () => process.exit(0), // OR on deno () => Deno.exit(0),
|
|
15
17
|
* // optional deno example
|
|
16
|
-
*
|
|
18
|
+
* listener = (eventName) => {
|
|
17
19
|
* const sig = Deno.signal(eventName);
|
|
18
20
|
* for await (const _ of sig) {
|
|
19
|
-
*
|
|
21
|
+
* exiting.correction(true);
|
|
20
22
|
* sig.dispose();
|
|
21
|
-
* Console.
|
|
23
|
+
* Console.log(`safe exit via "${eventName}"`);
|
|
22
24
|
* }
|
|
23
25
|
* }
|
|
24
26
|
* });
|
|
@@ -62,7 +64,7 @@ export class Setup {
|
|
|
62
64
|
* @example
|
|
63
65
|
* import { Setup } from 'vivth';
|
|
64
66
|
*
|
|
65
|
-
* Setup.workerThread({ parentPort: async () => await import('node:worker_threads') });
|
|
67
|
+
* Setup.workerThread({ parentPort: async () => (await import('node:worker_threads')).parentPort });
|
|
66
68
|
* // that is the default value, if your parentPort/equivalent API is not that;
|
|
67
69
|
* // you need to call this method;
|
|
68
70
|
*/
|
|
@@ -17,12 +17,18 @@ export class WorkerMainThread<WT extends WorkerThread> {
|
|
|
17
17
|
* - need to be called first, before any `WorkerMainThread` instantiation:
|
|
18
18
|
* @param {Object} param0
|
|
19
19
|
* @param {typeof WorkerMainThread["workerClass"]} param0.workerClass
|
|
20
|
+
* - example:
|
|
21
|
+
* ```js
|
|
22
|
+
* async () => await (import('worker_threads')).Worker
|
|
23
|
+
* ```
|
|
20
24
|
* @param {typeof WorkerMainThread["pathValidator"]} param0.pathValidator
|
|
25
|
+
* - example:
|
|
21
26
|
* ```js
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
27
|
+
* async (workerPath, root, base) => {
|
|
28
|
+
* const res = await fetch(`${root}/${base}/${workerPath}`);
|
|
29
|
+
* // might also check wheter it need base or not
|
|
30
|
+
* return await res.ok;
|
|
31
|
+
* }
|
|
26
32
|
* ```
|
|
27
33
|
* @param {typeof WorkerMainThread["basePath"]} [param0.basePath]
|
|
28
34
|
* - additonal realtivePath from rootPath;
|
|
@@ -17,12 +17,15 @@ export class WorkerThread<Receive, Post> {
|
|
|
17
17
|
* @template Receive_
|
|
18
18
|
* @template Post_
|
|
19
19
|
* @param {{parentPort:()=>Promise<any>}} parentPortRef
|
|
20
|
-
* - correct parentPort reference
|
|
20
|
+
* - correct parentPort reference, example:
|
|
21
|
+
* ```js
|
|
22
|
+
* async () => (await import('node:worker_threads')).parentPort
|
|
23
|
+
* ```
|
|
21
24
|
* @returns {typeof WorkerThread<Receive_, Post_>}
|
|
22
25
|
* @example
|
|
23
26
|
* import { WorkerThread } from 'vivth';
|
|
24
27
|
*
|
|
25
|
-
* WorkerThread.setup({ parentPort: async () => await import('node:worker_threads') });
|
|
28
|
+
* WorkerThread.setup({ parentPort: async () => (await import('node:worker_threads')).parentPort });
|
|
26
29
|
* // that is the default value, if your parentPort/equivalent API is not that;
|
|
27
30
|
* // you need to call this method;
|
|
28
31
|
*/
|