@vastblast/capnweb 0.7.3 → 0.7.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/dist/index-workers.cjs +27 -31
- package/dist/index-workers.cjs.map +1 -1
- package/dist/index-workers.js +27 -31
- package/dist/index-workers.js.map +1 -1
- package/dist/index.cjs +27 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +27 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2246,6 +2246,11 @@ var RpcSessionImpl = class {
|
|
|
2246
2246
|
this.transport.send(msgText).catch((err) => this.abort(err, false));
|
|
2247
2247
|
return msgText.length;
|
|
2248
2248
|
}
|
|
2249
|
+
isDirectFunctionCall(expression) {
|
|
2250
|
+
if (!(expression instanceof Array)) return false;
|
|
2251
|
+
let [kind, _id, path, args] = expression;
|
|
2252
|
+
return kind === "pipeline" && expression.length === 4 && path instanceof Array && path.length === 0 && args instanceof Array;
|
|
2253
|
+
}
|
|
2249
2254
|
sendCall(id, path, args) {
|
|
2250
2255
|
if (this.abortReason) throw this.abortReason;
|
|
2251
2256
|
let value = ["pipeline", id, path];
|
|
@@ -2374,7 +2379,11 @@ var RpcSessionImpl = class {
|
|
|
2374
2379
|
let payload = new Evaluator(this).evaluate(msg[1]);
|
|
2375
2380
|
let hook = new PayloadStubHook(payload);
|
|
2376
2381
|
hook.ignoreUnhandledRejections();
|
|
2382
|
+
let exportId = this.exports.length;
|
|
2377
2383
|
this.exports.push({ hook, refcount: 1 });
|
|
2384
|
+
if (this.isDirectFunctionCall(msg[1])) {
|
|
2385
|
+
this.ensureResolvingExport(exportId);
|
|
2386
|
+
}
|
|
2378
2387
|
continue;
|
|
2379
2388
|
}
|
|
2380
2389
|
break;
|
|
@@ -2447,6 +2456,8 @@ var RpcSessionImpl = class {
|
|
|
2447
2456
|
throw new Error(`bad RPC message: ${JSON.stringify(msg)}`);
|
|
2448
2457
|
}
|
|
2449
2458
|
}
|
|
2459
|
+
// Use a fresh cancellation promise for each read. Reusing one session-long promise here causes
|
|
2460
|
+
// Promise.race() to accumulate reactions until the session is shut down.
|
|
2450
2461
|
receiveOrAbort() {
|
|
2451
2462
|
let readCanceled = Promise.withResolvers();
|
|
2452
2463
|
this.cancelReadLoop = readCanceled.reject;
|
|
@@ -2509,7 +2520,6 @@ var RpcSession = class {
|
|
|
2509
2520
|
};
|
|
2510
2521
|
|
|
2511
2522
|
// src/websocket.ts
|
|
2512
|
-
var RESOLVED_VOID_PROMISE = Promise.resolve();
|
|
2513
2523
|
function newWebSocketRpcSession(webSocket, localMain, options) {
|
|
2514
2524
|
if (typeof webSocket === "string") {
|
|
2515
2525
|
webSocket = new WebSocket(webSocket);
|
|
@@ -2574,23 +2584,18 @@ var WebSocketTransport = class {
|
|
|
2574
2584
|
#receiveRejecter;
|
|
2575
2585
|
#receiveQueue = [];
|
|
2576
2586
|
#error;
|
|
2577
|
-
send(message) {
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
this.#sendQueue.push(message);
|
|
2583
|
-
}
|
|
2584
|
-
return RESOLVED_VOID_PROMISE;
|
|
2585
|
-
} catch (err) {
|
|
2586
|
-
return Promise.reject(err);
|
|
2587
|
+
async send(message) {
|
|
2588
|
+
if (this.#sendQueue === void 0) {
|
|
2589
|
+
this.#webSocket.send(message);
|
|
2590
|
+
} else {
|
|
2591
|
+
this.#sendQueue.push(message);
|
|
2587
2592
|
}
|
|
2588
2593
|
}
|
|
2589
|
-
receive() {
|
|
2594
|
+
async receive() {
|
|
2590
2595
|
if (this.#receiveQueue.length > 0) {
|
|
2591
|
-
return
|
|
2596
|
+
return this.#receiveQueue.shift();
|
|
2592
2597
|
} else if (this.#error) {
|
|
2593
|
-
|
|
2598
|
+
throw this.#error;
|
|
2594
2599
|
} else {
|
|
2595
2600
|
return new Promise((resolve, reject) => {
|
|
2596
2601
|
this.#receiveResolver = resolve;
|
|
@@ -2623,7 +2628,6 @@ var WebSocketTransport = class {
|
|
|
2623
2628
|
};
|
|
2624
2629
|
|
|
2625
2630
|
// src/batch.ts
|
|
2626
|
-
var RESOLVED_VOID_PROMISE2 = Promise.resolve();
|
|
2627
2631
|
var BatchClientTransport = class {
|
|
2628
2632
|
constructor(sendBatch) {
|
|
2629
2633
|
this.#promise = this.#scheduleBatch(sendBatch);
|
|
@@ -2632,11 +2636,10 @@ var BatchClientTransport = class {
|
|
|
2632
2636
|
#aborted;
|
|
2633
2637
|
#batchToSend = [];
|
|
2634
2638
|
#batchToReceive = null;
|
|
2635
|
-
send(message) {
|
|
2639
|
+
async send(message) {
|
|
2636
2640
|
if (this.#batchToSend !== null) {
|
|
2637
2641
|
this.#batchToSend.push(message);
|
|
2638
2642
|
}
|
|
2639
|
-
return RESOLVED_VOID_PROMISE2;
|
|
2640
2643
|
}
|
|
2641
2644
|
async receive() {
|
|
2642
2645
|
if (!this.#batchToReceive) {
|
|
@@ -2686,9 +2689,8 @@ var BatchServerTransport = class {
|
|
|
2686
2689
|
#batchToSend = [];
|
|
2687
2690
|
#batchToReceive;
|
|
2688
2691
|
#allReceived = Promise.withResolvers();
|
|
2689
|
-
send(message) {
|
|
2692
|
+
async send(message) {
|
|
2690
2693
|
this.#batchToSend.push(message);
|
|
2691
|
-
return RESOLVED_VOID_PROMISE2;
|
|
2692
2694
|
}
|
|
2693
2695
|
async receive() {
|
|
2694
2696
|
let msg = this.#batchToReceive.shift();
|
|
@@ -2746,7 +2748,6 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
|
|
|
2746
2748
|
}
|
|
2747
2749
|
|
|
2748
2750
|
// src/messageport.ts
|
|
2749
|
-
var RESOLVED_VOID_PROMISE3 = Promise.resolve();
|
|
2750
2751
|
function newMessagePortRpcSession(port, localMain, options) {
|
|
2751
2752
|
let transport = new MessagePortTransport(port);
|
|
2752
2753
|
let rpc = new RpcSession(transport, localMain, options);
|
|
@@ -2780,22 +2781,17 @@ var MessagePortTransport = class {
|
|
|
2780
2781
|
#receiveRejecter;
|
|
2781
2782
|
#receiveQueue = [];
|
|
2782
2783
|
#error;
|
|
2783
|
-
send(message) {
|
|
2784
|
+
async send(message) {
|
|
2784
2785
|
if (this.#error) {
|
|
2785
|
-
|
|
2786
|
-
}
|
|
2787
|
-
try {
|
|
2788
|
-
this.#port.postMessage(message);
|
|
2789
|
-
return RESOLVED_VOID_PROMISE3;
|
|
2790
|
-
} catch (err) {
|
|
2791
|
-
return Promise.reject(err);
|
|
2786
|
+
throw this.#error;
|
|
2792
2787
|
}
|
|
2788
|
+
this.#port.postMessage(message);
|
|
2793
2789
|
}
|
|
2794
|
-
receive() {
|
|
2790
|
+
async receive() {
|
|
2795
2791
|
if (this.#receiveQueue.length > 0) {
|
|
2796
|
-
return
|
|
2792
|
+
return this.#receiveQueue.shift();
|
|
2797
2793
|
} else if (this.#error) {
|
|
2798
|
-
|
|
2794
|
+
throw this.#error;
|
|
2799
2795
|
} else {
|
|
2800
2796
|
return new Promise((resolve, reject) => {
|
|
2801
2797
|
this.#receiveResolver = resolve;
|