@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-workers.cjs
CHANGED
|
@@ -2271,6 +2271,11 @@ var RpcSessionImpl = class {
|
|
|
2271
2271
|
this.transport.send(msgText).catch((err) => this.abort(err, false));
|
|
2272
2272
|
return msgText.length;
|
|
2273
2273
|
}
|
|
2274
|
+
isDirectFunctionCall(expression) {
|
|
2275
|
+
if (!(expression instanceof Array)) return false;
|
|
2276
|
+
let [kind, _id, path, args] = expression;
|
|
2277
|
+
return kind === "pipeline" && expression.length === 4 && path instanceof Array && path.length === 0 && args instanceof Array;
|
|
2278
|
+
}
|
|
2274
2279
|
sendCall(id, path, args) {
|
|
2275
2280
|
if (this.abortReason) throw this.abortReason;
|
|
2276
2281
|
let value = ["pipeline", id, path];
|
|
@@ -2399,7 +2404,11 @@ var RpcSessionImpl = class {
|
|
|
2399
2404
|
let payload = new Evaluator(this).evaluate(msg[1]);
|
|
2400
2405
|
let hook = new PayloadStubHook(payload);
|
|
2401
2406
|
hook.ignoreUnhandledRejections();
|
|
2407
|
+
let exportId = this.exports.length;
|
|
2402
2408
|
this.exports.push({ hook, refcount: 1 });
|
|
2409
|
+
if (this.isDirectFunctionCall(msg[1])) {
|
|
2410
|
+
this.ensureResolvingExport(exportId);
|
|
2411
|
+
}
|
|
2403
2412
|
continue;
|
|
2404
2413
|
}
|
|
2405
2414
|
break;
|
|
@@ -2472,6 +2481,8 @@ var RpcSessionImpl = class {
|
|
|
2472
2481
|
throw new Error(`bad RPC message: ${JSON.stringify(msg)}`);
|
|
2473
2482
|
}
|
|
2474
2483
|
}
|
|
2484
|
+
// Use a fresh cancellation promise for each read. Reusing one session-long promise here causes
|
|
2485
|
+
// Promise.race() to accumulate reactions until the session is shut down.
|
|
2475
2486
|
receiveOrAbort() {
|
|
2476
2487
|
let readCanceled = Promise.withResolvers();
|
|
2477
2488
|
this.cancelReadLoop = readCanceled.reject;
|
|
@@ -2534,7 +2545,6 @@ var RpcSession = class {
|
|
|
2534
2545
|
};
|
|
2535
2546
|
|
|
2536
2547
|
// src/websocket.ts
|
|
2537
|
-
var RESOLVED_VOID_PROMISE = Promise.resolve();
|
|
2538
2548
|
function newWebSocketRpcSession(webSocket, localMain, options) {
|
|
2539
2549
|
if (typeof webSocket === "string") {
|
|
2540
2550
|
webSocket = new WebSocket(webSocket);
|
|
@@ -2599,23 +2609,18 @@ var WebSocketTransport = class {
|
|
|
2599
2609
|
#receiveRejecter;
|
|
2600
2610
|
#receiveQueue = [];
|
|
2601
2611
|
#error;
|
|
2602
|
-
send(message) {
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
this.#sendQueue.push(message);
|
|
2608
|
-
}
|
|
2609
|
-
return RESOLVED_VOID_PROMISE;
|
|
2610
|
-
} catch (err) {
|
|
2611
|
-
return Promise.reject(err);
|
|
2612
|
+
async send(message) {
|
|
2613
|
+
if (this.#sendQueue === void 0) {
|
|
2614
|
+
this.#webSocket.send(message);
|
|
2615
|
+
} else {
|
|
2616
|
+
this.#sendQueue.push(message);
|
|
2612
2617
|
}
|
|
2613
2618
|
}
|
|
2614
|
-
receive() {
|
|
2619
|
+
async receive() {
|
|
2615
2620
|
if (this.#receiveQueue.length > 0) {
|
|
2616
|
-
return
|
|
2621
|
+
return this.#receiveQueue.shift();
|
|
2617
2622
|
} else if (this.#error) {
|
|
2618
|
-
|
|
2623
|
+
throw this.#error;
|
|
2619
2624
|
} else {
|
|
2620
2625
|
return new Promise((resolve, reject) => {
|
|
2621
2626
|
this.#receiveResolver = resolve;
|
|
@@ -2648,7 +2653,6 @@ var WebSocketTransport = class {
|
|
|
2648
2653
|
};
|
|
2649
2654
|
|
|
2650
2655
|
// src/batch.ts
|
|
2651
|
-
var RESOLVED_VOID_PROMISE2 = Promise.resolve();
|
|
2652
2656
|
var BatchClientTransport = class {
|
|
2653
2657
|
constructor(sendBatch) {
|
|
2654
2658
|
this.#promise = this.#scheduleBatch(sendBatch);
|
|
@@ -2657,11 +2661,10 @@ var BatchClientTransport = class {
|
|
|
2657
2661
|
#aborted;
|
|
2658
2662
|
#batchToSend = [];
|
|
2659
2663
|
#batchToReceive = null;
|
|
2660
|
-
send(message) {
|
|
2664
|
+
async send(message) {
|
|
2661
2665
|
if (this.#batchToSend !== null) {
|
|
2662
2666
|
this.#batchToSend.push(message);
|
|
2663
2667
|
}
|
|
2664
|
-
return RESOLVED_VOID_PROMISE2;
|
|
2665
2668
|
}
|
|
2666
2669
|
async receive() {
|
|
2667
2670
|
if (!this.#batchToReceive) {
|
|
@@ -2711,9 +2714,8 @@ var BatchServerTransport = class {
|
|
|
2711
2714
|
#batchToSend = [];
|
|
2712
2715
|
#batchToReceive;
|
|
2713
2716
|
#allReceived = Promise.withResolvers();
|
|
2714
|
-
send(message) {
|
|
2717
|
+
async send(message) {
|
|
2715
2718
|
this.#batchToSend.push(message);
|
|
2716
|
-
return RESOLVED_VOID_PROMISE2;
|
|
2717
2719
|
}
|
|
2718
2720
|
async receive() {
|
|
2719
2721
|
let msg = this.#batchToReceive.shift();
|
|
@@ -2771,7 +2773,6 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
|
|
|
2771
2773
|
}
|
|
2772
2774
|
|
|
2773
2775
|
// src/messageport.ts
|
|
2774
|
-
var RESOLVED_VOID_PROMISE3 = Promise.resolve();
|
|
2775
2776
|
function newMessagePortRpcSession(port, localMain, options) {
|
|
2776
2777
|
let transport = new MessagePortTransport(port);
|
|
2777
2778
|
let rpc = new RpcSession(transport, localMain, options);
|
|
@@ -2805,22 +2806,17 @@ var MessagePortTransport = class {
|
|
|
2805
2806
|
#receiveRejecter;
|
|
2806
2807
|
#receiveQueue = [];
|
|
2807
2808
|
#error;
|
|
2808
|
-
send(message) {
|
|
2809
|
+
async send(message) {
|
|
2809
2810
|
if (this.#error) {
|
|
2810
|
-
|
|
2811
|
-
}
|
|
2812
|
-
try {
|
|
2813
|
-
this.#port.postMessage(message);
|
|
2814
|
-
return RESOLVED_VOID_PROMISE3;
|
|
2815
|
-
} catch (err) {
|
|
2816
|
-
return Promise.reject(err);
|
|
2811
|
+
throw this.#error;
|
|
2817
2812
|
}
|
|
2813
|
+
this.#port.postMessage(message);
|
|
2818
2814
|
}
|
|
2819
|
-
receive() {
|
|
2815
|
+
async receive() {
|
|
2820
2816
|
if (this.#receiveQueue.length > 0) {
|
|
2821
|
-
return
|
|
2817
|
+
return this.#receiveQueue.shift();
|
|
2822
2818
|
} else if (this.#error) {
|
|
2823
|
-
|
|
2819
|
+
throw this.#error;
|
|
2824
2820
|
} else {
|
|
2825
2821
|
return new Promise((resolve, reject) => {
|
|
2826
2822
|
this.#receiveResolver = resolve;
|