@lynx-js/web-worker-rpc-canary 0.19.2 → 0.19.3-canary-20251223-986761dd
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/CHANGELOG.md +6 -0
- package/dist/Rpc.d.ts +5 -1
- package/dist/Rpc.js +36 -5
- package/dist/index.d.ts +1 -1
- package/package.json +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @lynx-js/web-worker-rpc
|
|
2
2
|
|
|
3
|
+
## 0.19.3-canary-20251223134821-986761dd1e9e631f8118faec68188f29f78e9236
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: support lazy message port assigning in web-worker-rpc ([#2040](https://github.com/lynx-family/lynx-stack/pull/2040))
|
|
8
|
+
|
|
3
9
|
## 0.19.2
|
|
4
10
|
|
|
5
11
|
## 0.19.1
|
package/dist/Rpc.d.ts
CHANGED
|
@@ -15,7 +15,11 @@ export declare class Rpc {
|
|
|
15
15
|
* @param port one size of a message channel
|
|
16
16
|
* @param name instance name
|
|
17
17
|
*/
|
|
18
|
-
constructor(port: MessagePort, name: string);
|
|
18
|
+
constructor(port: MessagePort | undefined, name: string);
|
|
19
|
+
setMessagePort(port: MessagePort): void;
|
|
20
|
+
postMessage(message: unknown, detail?: {
|
|
21
|
+
transfer: Transferable[];
|
|
22
|
+
}): void;
|
|
19
23
|
get nextRetId(): string;
|
|
20
24
|
/**
|
|
21
25
|
* @private do not use this
|
package/dist/Rpc.js
CHANGED
|
@@ -5,6 +5,7 @@ export class Rpc {
|
|
|
5
5
|
port;
|
|
6
6
|
name;
|
|
7
7
|
incId = 0;
|
|
8
|
+
#messageQueue = [];
|
|
8
9
|
#messageCache = {};
|
|
9
10
|
#textEncoder = new TextEncoder();
|
|
10
11
|
#textDecoder = new TextDecoder();
|
|
@@ -16,7 +17,33 @@ export class Rpc {
|
|
|
16
17
|
constructor(port, name) {
|
|
17
18
|
this.port = port;
|
|
18
19
|
this.name = name;
|
|
19
|
-
|
|
20
|
+
if (port) {
|
|
21
|
+
port.onmessage = (ev) => this.#onMessage(ev.data);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
setMessagePort(port) {
|
|
25
|
+
if (this.port) {
|
|
26
|
+
throw new Error('Rpc port already set');
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.port = port;
|
|
30
|
+
for (const item of this.#messageQueue) {
|
|
31
|
+
this.postMessage(item.message, item.detail);
|
|
32
|
+
}
|
|
33
|
+
this.#messageQueue = [];
|
|
34
|
+
port.onmessage = (ev) => this.#onMessage(ev.data);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
postMessage(message, detail) {
|
|
38
|
+
if (this.port) {
|
|
39
|
+
this.port.postMessage(message, detail);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.#messageQueue.push({
|
|
43
|
+
message: message,
|
|
44
|
+
detail,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
20
47
|
}
|
|
21
48
|
get nextRetId() {
|
|
22
49
|
return `ret_${this.name}_${this.incId++}`;
|
|
@@ -161,7 +188,7 @@ export class Rpc {
|
|
|
161
188
|
lock: lock,
|
|
162
189
|
buf: sharedBuffer,
|
|
163
190
|
};
|
|
164
|
-
this.
|
|
191
|
+
this.postMessage(message, { transfer });
|
|
165
192
|
Atomics.wait(lockViewer, 0, 0);
|
|
166
193
|
if (lockViewer[0] === 2) {
|
|
167
194
|
// error
|
|
@@ -183,7 +210,11 @@ export class Rpc {
|
|
|
183
210
|
}
|
|
184
211
|
else {
|
|
185
212
|
if (endpoint.hasReturn) {
|
|
186
|
-
|
|
213
|
+
let promise, resolve, reject;
|
|
214
|
+
promise = new Promise((res, rej) => {
|
|
215
|
+
resolve = res;
|
|
216
|
+
reject = rej;
|
|
217
|
+
});
|
|
187
218
|
const retHandler = Rpc.createRetEndpoint(this.nextRetId);
|
|
188
219
|
this.registerHandler(retHandler, (returnValue, error) => {
|
|
189
220
|
if (error)
|
|
@@ -197,7 +228,7 @@ export class Rpc {
|
|
|
197
228
|
retId: retHandler?.name,
|
|
198
229
|
hasTransfer: endpoint.hasReturnTransfer,
|
|
199
230
|
};
|
|
200
|
-
this.
|
|
231
|
+
this.postMessage(message, { transfer });
|
|
201
232
|
return promise;
|
|
202
233
|
}
|
|
203
234
|
else {
|
|
@@ -206,7 +237,7 @@ export class Rpc {
|
|
|
206
237
|
data: parameters,
|
|
207
238
|
sync: false,
|
|
208
239
|
};
|
|
209
|
-
this.
|
|
240
|
+
this.postMessage(message, { transfer });
|
|
210
241
|
}
|
|
211
242
|
}
|
|
212
243
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Rpc } from './Rpc.js';
|
|
2
|
-
export type { RpcEndpoint, RpcEndpointSync, RpcEndpointSyncVoid, } from './RpcEndpoint.js';
|
|
2
|
+
export type { RpcEndpoint, RpcEndpointSync, RpcEndpointSyncVoid, RpcEndpointAsync, RpcEndpointAsyncVoid, RpcEndpointAsyncWithTransfer, } from './RpcEndpoint.js';
|
|
3
3
|
export { createRpcEndpoint } from './RpcEndpoint.js';
|
|
4
4
|
export type * from './TypeUtils.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-worker-rpc-canary",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.3-canary-20251223-986761dd",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
},
|
|
12
12
|
"license": "Apache-2.0",
|
|
13
13
|
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js",
|
|
18
|
+
"source": "./src/index.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
14
21
|
"main": "dist/index.js",
|
|
15
22
|
"typings": "dist/index.d.ts",
|
|
16
23
|
"files": [
|
|
@@ -20,5 +27,8 @@
|
|
|
20
27
|
"Notice.txt",
|
|
21
28
|
"CHANGELOG.md",
|
|
22
29
|
"README.md"
|
|
23
|
-
]
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"test": "vitest"
|
|
33
|
+
}
|
|
24
34
|
}
|