vivth 1.4.4 → 1.4.5
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 +7 -6
- package/package.json +1 -1
- package/src/class/WorkerMainThread.mjs +8 -7
- package/src/class/WorkerMainThreadBundled.mjs +8 -7
- package/src/class/WorkerThread.mjs +5 -4
- package/types/src/class/WorkerMainThread.d.mts +7 -7
- package/types/src/class/WorkerMainThreadBundled.d.mts +7 -7
- 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
|
```
|
|
@@ -2695,7 +2695,7 @@ myDoubleWorker.postMessage(90);
|
|
|
2695
2695
|
/**
|
|
2696
2696
|
* @template RECEIVE
|
|
2697
2697
|
* @template POST
|
|
2698
|
-
* @param {{parentPort:import('worker_threads')["parentPort"]}} refs
|
|
2698
|
+
* @param {{parentPort:import('node:worker_threads')["parentPort"]}} refs
|
|
2699
2699
|
* -example:
|
|
2700
2700
|
* ```js
|
|
2701
2701
|
* import { parentPort } from 'node:worker_threads';
|
|
@@ -2728,7 +2728,7 @@ export const MyWorkerThreadRef = WorkerThread.setup({ parentPort });
|
|
|
2728
2728
|
```js
|
|
2729
2729
|
import { MyWorkerThread } from "./MyWorkerThread.mjs";
|
|
2730
2730
|
|
|
2731
|
-
const
|
|
2731
|
+
const handler = async (ev, isLastOnQ) => {
|
|
2732
2732
|
// if(!isLastOnQ()) {
|
|
2733
2733
|
// return null; // can be used for imperative debouncing;
|
|
2734
2734
|
// }
|
|
@@ -2737,7 +2737,8 @@ const doubleWorker = new MyWorkerThread((ev, isLastOnQ) => {
|
|
|
2737
2737
|
// return;
|
|
2738
2738
|
// }
|
|
2739
2739
|
return (ev = ev * 2);
|
|
2740
|
-
}
|
|
2740
|
+
};
|
|
2741
|
+
new MyWorkerThread(handler);
|
|
2741
2742
|
```
|
|
2742
2743
|
|
|
2743
2744
|
#### reference:`WorkerThread_instance.handler`
|
|
@@ -2746,7 +2747,7 @@ const doubleWorker = new MyWorkerThread((ev, isLastOnQ) => {
|
|
|
2746
2747
|
|
|
2747
2748
|
```js
|
|
2748
2749
|
/**
|
|
2749
|
-
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => POST}
|
|
2750
|
+
* @type {(ev: RECEIVE, isLastOnQ:QCBReturn["isLastOnQ"]) => Promise<POST>}
|
|
2750
2751
|
*/
|
|
2751
2752
|
```
|
|
2752
2753
|
|
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>}
|
|
@@ -246,7 +247,7 @@ export class WorkerMainThread {
|
|
|
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);
|
|
@@ -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>}
|
|
@@ -179,7 +180,7 @@ export class WorkerMainThread {
|
|
|
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);
|
|
@@ -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
|
|
@@ -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,26 +38,26 @@ 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]
|
|
@@ -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;
|