vivth 1.4.4 → 1.4.6
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 +11 -7
- package/package.json +1 -1
- package/src/class/WorkerMainThread.mjs +17 -10
- package/src/class/WorkerMainThreadBundled.mjs +15 -10
- package/src/class/WorkerThread.mjs +5 -4
- package/types/src/class/WorkerMainThread.d.mts +12 -9
- package/types/src/class/WorkerMainThreadBundled.d.mts +10 -9
- package/types/src/class/WorkerThread.d.mts +7 -6
package/README.md
CHANGED
|
@@ -2548,7 +2548,7 @@ WorkerMainThread.setup({
|
|
|
2548
2548
|
|
|
2549
2549
|
```js
|
|
2550
2550
|
/**
|
|
2551
|
-
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
2551
|
+
* @type {typeof Worker|typeof import('node:worker_threads').Worker}
|
|
2552
2552
|
*/
|
|
2553
2553
|
```
|
|
2554
2554
|
|
|
@@ -2570,7 +2570,7 @@ WorkerMainThread.setup({
|
|
|
2570
2570
|
```js
|
|
2571
2571
|
/**
|
|
2572
2572
|
* @param {string} handler
|
|
2573
|
-
* @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
2573
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
2574
2574
|
* @returns {WorkerMainThread<WT>}
|
|
2575
2575
|
*/
|
|
2576
2576
|
```
|
|
@@ -2591,7 +2591,10 @@ export const myDoubleWorker = WorkerMainThread.newVivthWorker(
|
|
|
2591
2591
|
|
|
2592
2592
|
```js
|
|
2593
2593
|
/**
|
|
2594
|
-
* @
|
|
2594
|
+
* @param {boolean} terminateAllReactivity
|
|
2595
|
+
* - false: only terminate `Worker` instance;
|
|
2596
|
+
* - true: also terminate `Signal`s and `Effect`s;
|
|
2597
|
+
* @return {void}
|
|
2595
2598
|
*/
|
|
2596
2599
|
```
|
|
2597
2600
|
|
|
@@ -2695,7 +2698,7 @@ myDoubleWorker.postMessage(90);
|
|
|
2695
2698
|
/**
|
|
2696
2699
|
* @template RECEIVE
|
|
2697
2700
|
* @template POST
|
|
2698
|
-
* @param {{parentPort:import('worker_threads')["parentPort"]}} refs
|
|
2701
|
+
* @param {{parentPort:import('node:worker_threads')["parentPort"]}} refs
|
|
2699
2702
|
* -example:
|
|
2700
2703
|
* ```js
|
|
2701
2704
|
* import { parentPort } from 'node:worker_threads';
|
|
@@ -2728,7 +2731,7 @@ export const MyWorkerThreadRef = WorkerThread.setup({ parentPort });
|
|
|
2728
2731
|
```js
|
|
2729
2732
|
import { MyWorkerThread } from "./MyWorkerThread.mjs";
|
|
2730
2733
|
|
|
2731
|
-
const
|
|
2734
|
+
const handler = async (ev, isLastOnQ) => {
|
|
2732
2735
|
// if(!isLastOnQ()) {
|
|
2733
2736
|
// return null; // can be used for imperative debouncing;
|
|
2734
2737
|
// }
|
|
@@ -2737,7 +2740,8 @@ const doubleWorker = new MyWorkerThread((ev, isLastOnQ) => {
|
|
|
2737
2740
|
// return;
|
|
2738
2741
|
// }
|
|
2739
2742
|
return (ev = ev * 2);
|
|
2740
|
-
}
|
|
2743
|
+
};
|
|
2744
|
+
new MyWorkerThread(handler);
|
|
2741
2745
|
```
|
|
2742
2746
|
|
|
2743
2747
|
#### reference:`WorkerThread_instance.handler`
|
|
@@ -2746,7 +2750,7 @@ const doubleWorker = new MyWorkerThread((ev, isLastOnQ) => {
|
|
|
2746
2750
|
|
|
2747
2751
|
```js
|
|
2748
2752
|
/**
|
|
2749
|
-
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => POST}
|
|
2753
|
+
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => Promise<POST>}
|
|
2750
2754
|
*/
|
|
2751
2755
|
```
|
|
2752
2756
|
|
package/package.json
CHANGED
|
@@ -88,7 +88,7 @@ export class WorkerMainThread {
|
|
|
88
88
|
* @description
|
|
89
89
|
* - reference for `Worker` class;
|
|
90
90
|
* - edit via `setup`;
|
|
91
|
-
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
91
|
+
* @type {typeof Worker|typeof import('node:worker_threads').Worker}
|
|
92
92
|
*/
|
|
93
93
|
static workerClass;
|
|
94
94
|
/**
|
|
@@ -98,15 +98,16 @@ export class WorkerMainThread {
|
|
|
98
98
|
* @type {(paths:{worker: string, root:string})=>Promise<string>}
|
|
99
99
|
*/
|
|
100
100
|
static pathValidator;
|
|
101
|
-
static #options =
|
|
102
|
-
type: 'module'
|
|
103
|
-
|
|
101
|
+
static #options =
|
|
102
|
+
/** @type {import('node:worker_threads').WorkerOptions & { type?: 'module' }} */ ({
|
|
103
|
+
type: 'module',
|
|
104
|
+
});
|
|
104
105
|
/**
|
|
105
106
|
* @template {WorkerThread<any, any>} WT
|
|
106
107
|
* @description
|
|
107
108
|
* - create Worker_instance;
|
|
108
109
|
* @param {string} handler
|
|
109
|
-
* @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
110
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
110
111
|
* @returns {WorkerMainThread<WT>}
|
|
111
112
|
* @example
|
|
112
113
|
* import { WorkerMainThread } from 'vivth';
|
|
@@ -144,7 +145,7 @@ export class WorkerMainThread {
|
|
|
144
145
|
* @template {WorkerThread<any, any>} WT
|
|
145
146
|
* @param {string} handler
|
|
146
147
|
* @param { WorkerOptions
|
|
147
|
-
* | import('worker_threads').WorkerOptions} options
|
|
148
|
+
* | import('node:worker_threads').WorkerOptions} options
|
|
148
149
|
* @param {WorkerMainThread<WT>} worker
|
|
149
150
|
* @param {(any:any)=>void} listener
|
|
150
151
|
* @returns {Promise<void>}
|
|
@@ -240,13 +241,13 @@ export class WorkerMainThread {
|
|
|
240
241
|
if (worker.#worker.value) {
|
|
241
242
|
worker.#worker.value.postMessage(closeWorkerThreadEventObject, []);
|
|
242
243
|
}
|
|
243
|
-
worker.terminate();
|
|
244
|
+
worker.terminate(true);
|
|
244
245
|
});
|
|
245
246
|
}
|
|
246
247
|
}
|
|
247
248
|
/**
|
|
248
249
|
* lazyly generated because node version need to await
|
|
249
|
-
* @type {Signal<Worker | import('worker_threads').Worker>}
|
|
250
|
+
* @type {Signal<Worker | import('node:worker_threads').Worker>}
|
|
250
251
|
*/
|
|
251
252
|
// @ts-expect-error
|
|
252
253
|
#worker = new Signal(undefined);
|
|
@@ -265,13 +266,19 @@ export class WorkerMainThread {
|
|
|
265
266
|
/**
|
|
266
267
|
* @description
|
|
267
268
|
* - terminate all signals that are used on this instance;
|
|
268
|
-
* @
|
|
269
|
+
* @param {boolean} terminateAllReactivity
|
|
270
|
+
* - false: only terminate `Worker` instance;
|
|
271
|
+
* - true: also terminate `Signal`s and `Effect`s;
|
|
272
|
+
* @return {void}
|
|
269
273
|
*/
|
|
270
|
-
terminate = () => {
|
|
274
|
+
terminate = (terminateAllReactivity) => {
|
|
271
275
|
/**
|
|
272
276
|
* this is more for browser, as most of this are automatically cleaned with `SafeExit`;
|
|
273
277
|
*/
|
|
274
278
|
this.#worker.value?.terminate();
|
|
279
|
+
if (!terminateAllReactivity) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
275
282
|
this.#worker.remove.ref();
|
|
276
283
|
this.#handler.options.removeEffect();
|
|
277
284
|
this.#proxyPost.remove.ref();
|
|
@@ -51,20 +51,21 @@ export class WorkerMainThread {
|
|
|
51
51
|
WorkerMainThread.pathValidator = pathValidator;
|
|
52
52
|
};
|
|
53
53
|
/**
|
|
54
|
-
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
54
|
+
* @type {typeof Worker|typeof import('node:worker_threads').Worker}
|
|
55
55
|
*/
|
|
56
56
|
static workerClass;
|
|
57
57
|
/**
|
|
58
58
|
* @type {(paths:{worker: string, root:string})=>Promise<string>}
|
|
59
59
|
*/
|
|
60
60
|
static pathValidator;
|
|
61
|
-
static #options =
|
|
62
|
-
type: 'module'
|
|
63
|
-
|
|
61
|
+
static #options =
|
|
62
|
+
/** @type {import('node:worker_threads').WorkerOptions & { type?: 'module' }} */ ({
|
|
63
|
+
type: 'module',
|
|
64
|
+
});
|
|
64
65
|
/**
|
|
65
66
|
* @template {WorkerThread<any, any>} WT
|
|
66
67
|
* @param {string} handler
|
|
67
|
-
* @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
68
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
68
69
|
* @returns {WorkerMainThread<WT>}
|
|
69
70
|
*/
|
|
70
71
|
static newVivthWorker(handler, options = {}) {
|
|
@@ -93,7 +94,7 @@ export class WorkerMainThread {
|
|
|
93
94
|
* @template {WorkerThread<any, any>} WT
|
|
94
95
|
* @param {string} handler
|
|
95
96
|
* @param { WorkerOptions
|
|
96
|
-
* | import('worker_threads').WorkerOptions} options
|
|
97
|
+
* | import('node:worker_threads').WorkerOptions} options
|
|
97
98
|
* @param {WorkerMainThread<WT>} worker
|
|
98
99
|
* @param {(any:any)=>void} listener
|
|
99
100
|
* @returns {Promise<void>}
|
|
@@ -173,13 +174,13 @@ export class WorkerMainThread {
|
|
|
173
174
|
if (worker.#worker.value) {
|
|
174
175
|
worker.#worker.value.postMessage(closeWorkerThreadEventObject, []);
|
|
175
176
|
}
|
|
176
|
-
worker.terminate();
|
|
177
|
+
worker.terminate(true);
|
|
177
178
|
});
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
/**
|
|
181
182
|
* lazyly generated because node version need to await
|
|
182
|
-
* @type {Signal<Worker | import('worker_threads').Worker>}
|
|
183
|
+
* @type {Signal<Worker | import('node:worker_threads').Worker>}
|
|
183
184
|
*/
|
|
184
185
|
// @ts-expect-error
|
|
185
186
|
#worker = new Signal(undefined);
|
|
@@ -196,13 +197,17 @@ export class WorkerMainThread {
|
|
|
196
197
|
worker.postMessage(postData, []);
|
|
197
198
|
});
|
|
198
199
|
/**
|
|
199
|
-
* @
|
|
200
|
+
* @param {boolean} [terminateAllReactivity]
|
|
201
|
+
* @return {void}
|
|
200
202
|
*/
|
|
201
|
-
terminate = () => {
|
|
203
|
+
terminate = (terminateAllReactivity = false) => {
|
|
202
204
|
/**
|
|
203
205
|
* this is more for browser, as most of this are automatically cleaned with `SafeExit`;
|
|
204
206
|
*/
|
|
205
207
|
this.#worker.value?.terminate();
|
|
208
|
+
if (!terminateAllReactivity) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
206
211
|
this.#worker.remove.ref();
|
|
207
212
|
this.#handler.options.removeEffect();
|
|
208
213
|
this.#proxyPost.remove.ref();
|
|
@@ -28,7 +28,7 @@ export class WorkerThread {
|
|
|
28
28
|
* - need to be called and exported as new `WorkerThread` class reference;
|
|
29
29
|
* @template RECEIVE
|
|
30
30
|
* @template POST
|
|
31
|
-
* @param {{parentPort:import('worker_threads')["parentPort"]}} refs
|
|
31
|
+
* @param {{parentPort:import('node:worker_threads')["parentPort"]}} refs
|
|
32
32
|
* -example:
|
|
33
33
|
* ```js
|
|
34
34
|
* import { parentPort } from 'node:worker_threads';
|
|
@@ -61,7 +61,7 @@ export class WorkerThread {
|
|
|
61
61
|
* @example
|
|
62
62
|
* import { MyWorkerThread } from './MyWorkerThread.mjs';
|
|
63
63
|
*
|
|
64
|
-
* const
|
|
64
|
+
* const handler = async (ev, isLastOnQ) => {
|
|
65
65
|
* // if(!isLastOnQ()) {
|
|
66
66
|
* // return null; // can be used for imperative debouncing;
|
|
67
67
|
* // }
|
|
@@ -70,7 +70,8 @@ export class WorkerThread {
|
|
|
70
70
|
* // return;
|
|
71
71
|
* // }
|
|
72
72
|
* return ev = ev \* 2;
|
|
73
|
-
* }
|
|
73
|
+
* }
|
|
74
|
+
* new MyWorkerThread(handler);
|
|
74
75
|
*/
|
|
75
76
|
constructor(handler) {
|
|
76
77
|
this.handler = handler;
|
|
@@ -154,7 +155,7 @@ export class WorkerThread {
|
|
|
154
155
|
/**
|
|
155
156
|
* @description
|
|
156
157
|
* - type helper;
|
|
157
|
-
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => POST}
|
|
158
|
+
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => Promise<POST>}
|
|
158
159
|
*/
|
|
159
160
|
handler;
|
|
160
161
|
/**
|
|
@@ -66,9 +66,9 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
|
|
|
66
66
|
* @description
|
|
67
67
|
* - reference for `Worker` class;
|
|
68
68
|
* - edit via `setup`;
|
|
69
|
-
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
69
|
+
* @type {typeof Worker|typeof import('node:worker_threads').Worker}
|
|
70
70
|
*/
|
|
71
|
-
static workerClass: typeof Worker | typeof import("worker_threads").Worker;
|
|
71
|
+
static workerClass: typeof Worker | typeof import("node:worker_threads").Worker;
|
|
72
72
|
/**
|
|
73
73
|
* @description
|
|
74
74
|
* - reference for validating path;
|
|
@@ -79,7 +79,7 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
|
|
|
79
79
|
worker: string;
|
|
80
80
|
root: string;
|
|
81
81
|
}) => Promise<string>;
|
|
82
|
-
static "__#private@#options": import("worker_threads").WorkerOptions & {
|
|
82
|
+
static "__#private@#options": import("node:worker_threads").WorkerOptions & {
|
|
83
83
|
type?: "module";
|
|
84
84
|
};
|
|
85
85
|
/**
|
|
@@ -87,24 +87,24 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
|
|
|
87
87
|
* @description
|
|
88
88
|
* - create Worker_instance;
|
|
89
89
|
* @param {string} handler
|
|
90
|
-
* @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
90
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
91
91
|
* @returns {WorkerMainThread<WT>}
|
|
92
92
|
* @example
|
|
93
93
|
* import { WorkerMainThread } from 'vivth';
|
|
94
94
|
*
|
|
95
95
|
* export const myDoubleWorker = WorkerMainThread.newVivthWorker('./doubleWorkerThread.mjs');
|
|
96
96
|
*/
|
|
97
|
-
static newVivthWorker<WT_1 extends WorkerThread<any, any>>(handler: string, options?: Omit<WorkerOptions | import("worker_threads").WorkerOptions, "eval" | "type">): WorkerMainThread<WT_1>;
|
|
97
|
+
static newVivthWorker<WT_1 extends WorkerThread<any, any>>(handler: string, options?: Omit<WorkerOptions | import("node:worker_threads").WorkerOptions, "eval" | "type">): WorkerMainThread<WT_1>;
|
|
98
98
|
/**
|
|
99
99
|
* @template {WorkerThread<any, any>} WT
|
|
100
100
|
* @param {string} handler
|
|
101
101
|
* @param { WorkerOptions
|
|
102
|
-
* | import('worker_threads').WorkerOptions} options
|
|
102
|
+
* | import('node:worker_threads').WorkerOptions} options
|
|
103
103
|
* @param {WorkerMainThread<WT>} worker
|
|
104
104
|
* @param {(any:any)=>void} listener
|
|
105
105
|
* @returns {Promise<void>}
|
|
106
106
|
*/
|
|
107
|
-
static "__#private@#workerFilehandler"<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
|
|
107
|
+
static "__#private@#workerFilehandler"<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("node:worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
|
|
108
108
|
/**
|
|
109
109
|
* @private
|
|
110
110
|
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
|
|
@@ -118,9 +118,12 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
|
|
|
118
118
|
/**
|
|
119
119
|
* @description
|
|
120
120
|
* - terminate all signals that are used on this instance;
|
|
121
|
-
* @
|
|
121
|
+
* @param {boolean} terminateAllReactivity
|
|
122
|
+
* - false: only terminate `Worker` instance;
|
|
123
|
+
* - true: also terminate `Signal`s and `Effect`s;
|
|
124
|
+
* @return {void}
|
|
122
125
|
*/
|
|
123
|
-
terminate: () => void;
|
|
126
|
+
terminate: (terminateAllReactivity: boolean) => void;
|
|
124
127
|
/**
|
|
125
128
|
* @description
|
|
126
129
|
* - result signal of the processed message;
|
|
@@ -28,9 +28,9 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
|
|
|
28
28
|
pathValidator: (typeof WorkerMainThread)["pathValidator"];
|
|
29
29
|
}) => void;
|
|
30
30
|
/**
|
|
31
|
-
* @type {typeof Worker|typeof import('worker_threads').Worker}
|
|
31
|
+
* @type {typeof Worker|typeof import('node:worker_threads').Worker}
|
|
32
32
|
*/
|
|
33
|
-
static workerClass: typeof Worker | typeof import("worker_threads").Worker;
|
|
33
|
+
static workerClass: typeof Worker | typeof import("node:worker_threads").Worker;
|
|
34
34
|
/**
|
|
35
35
|
* @type {(paths:{worker: string, root:string})=>Promise<string>}
|
|
36
36
|
*/
|
|
@@ -38,35 +38,36 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
|
|
|
38
38
|
worker: string;
|
|
39
39
|
root: string;
|
|
40
40
|
}) => Promise<string>;
|
|
41
|
-
static "__#private@#options": import("worker_threads").WorkerOptions & {
|
|
41
|
+
static "__#private@#options": import("node:worker_threads").WorkerOptions & {
|
|
42
42
|
type?: "module";
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* @template {WorkerThread<any, any>} WT
|
|
46
46
|
* @param {string} handler
|
|
47
|
-
* @param {Omit<WorkerOptions|import('worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
47
|
+
* @param {Omit<WorkerOptions|import('node:worker_threads').WorkerOptions, 'eval'|'type'>} [options]
|
|
48
48
|
* @returns {WorkerMainThread<WT>}
|
|
49
49
|
*/
|
|
50
|
-
static newVivthWorker<WT_1 extends WorkerThread<any, any>>(handler: string, options?: Omit<WorkerOptions | import("worker_threads").WorkerOptions, "eval" | "type">): WorkerMainThread<WT_1>;
|
|
50
|
+
static newVivthWorker<WT_1 extends WorkerThread<any, any>>(handler: string, options?: Omit<WorkerOptions | import("node:worker_threads").WorkerOptions, "eval" | "type">): WorkerMainThread<WT_1>;
|
|
51
51
|
/**
|
|
52
52
|
* @template {WorkerThread<any, any>} WT
|
|
53
53
|
* @param {string} handler
|
|
54
54
|
* @param { WorkerOptions
|
|
55
|
-
* | import('worker_threads').WorkerOptions} options
|
|
55
|
+
* | import('node:worker_threads').WorkerOptions} options
|
|
56
56
|
* @param {WorkerMainThread<WT>} worker
|
|
57
57
|
* @param {(any:any)=>void} listener
|
|
58
58
|
* @returns {Promise<void>}
|
|
59
59
|
*/
|
|
60
|
-
static "__#private@#workerFilehandler"<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
|
|
60
|
+
static "__#private@#workerFilehandler"<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("node:worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
|
|
61
61
|
/**
|
|
62
62
|
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
|
|
63
63
|
* @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[1]} [options]
|
|
64
64
|
*/
|
|
65
65
|
constructor(handler: Parameters<(typeof WorkerMainThread<WT>)["newVivthWorker"]>[0], options?: Parameters<(typeof WorkerMainThread<WT>)["newVivthWorker"]>[1]);
|
|
66
66
|
/**
|
|
67
|
-
* @
|
|
67
|
+
* @param {boolean} [terminateAllReactivity]
|
|
68
|
+
* @return {void}
|
|
68
69
|
*/
|
|
69
|
-
terminate: () => void;
|
|
70
|
+
terminate: (terminateAllReactivity?: boolean) => void;
|
|
70
71
|
/**
|
|
71
72
|
* @type {Derived<WorkerResult<WT["POST"]>>}
|
|
72
73
|
*/
|
|
@@ -18,7 +18,7 @@ export class WorkerThread<RECEIVE, POST> {
|
|
|
18
18
|
* - need to be called and exported as new `WorkerThread` class reference;
|
|
19
19
|
* @template RECEIVE
|
|
20
20
|
* @template POST
|
|
21
|
-
* @param {{parentPort:import('worker_threads')["parentPort"]}} refs
|
|
21
|
+
* @param {{parentPort:import('node:worker_threads')["parentPort"]}} refs
|
|
22
22
|
* -example:
|
|
23
23
|
* ```js
|
|
24
24
|
* import { parentPort } from 'node:worker_threads';
|
|
@@ -31,7 +31,7 @@ export class WorkerThread<RECEIVE, POST> {
|
|
|
31
31
|
* export const MyWorkerThreadRef = WorkerThread.setup({ parentPort });
|
|
32
32
|
*/
|
|
33
33
|
static setup<RECEIVE_1, POST_1>(refs: {
|
|
34
|
-
parentPort: typeof import("worker_threads")["parentPort"];
|
|
34
|
+
parentPort: typeof import("node:worker_threads")["parentPort"];
|
|
35
35
|
}): typeof WorkerThread<RECEIVE_1, POST_1>;
|
|
36
36
|
/**
|
|
37
37
|
* @param {any} ev
|
|
@@ -44,7 +44,7 @@ export class WorkerThread<RECEIVE, POST> {
|
|
|
44
44
|
* @example
|
|
45
45
|
* import { MyWorkerThread } from './MyWorkerThread.mjs';
|
|
46
46
|
*
|
|
47
|
-
* const
|
|
47
|
+
* const handler = async (ev, isLastOnQ) => {
|
|
48
48
|
* // if(!isLastOnQ()) {
|
|
49
49
|
* // return null; // can be used for imperative debouncing;
|
|
50
50
|
* // }
|
|
@@ -53,15 +53,16 @@ export class WorkerThread<RECEIVE, POST> {
|
|
|
53
53
|
* // return;
|
|
54
54
|
* // }
|
|
55
55
|
* return ev = ev \* 2;
|
|
56
|
-
* }
|
|
56
|
+
* }
|
|
57
|
+
* new MyWorkerThread(handler);
|
|
57
58
|
*/
|
|
58
59
|
constructor(handler: WorkerThread<RECEIVE, POST>["handler"]);
|
|
59
60
|
/**
|
|
60
61
|
* @description
|
|
61
62
|
* - type helper;
|
|
62
|
-
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => POST}
|
|
63
|
+
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => Promise<POST>}
|
|
63
64
|
*/
|
|
64
|
-
handler: (ev: RECEIVE, isLastOnQ: () => boolean) => POST
|
|
65
|
+
handler: (ev: RECEIVE, isLastOnQ: () => boolean) => Promise<POST>;
|
|
65
66
|
/**
|
|
66
67
|
* @description
|
|
67
68
|
* - helper type, hold no actual value;
|