@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.js
CHANGED
|
@@ -2249,6 +2249,11 @@ var RpcSessionImpl = class {
|
|
|
2249
2249
|
this.transport.send(msgText).catch((err) => this.abort(err, false));
|
|
2250
2250
|
return msgText.length;
|
|
2251
2251
|
}
|
|
2252
|
+
isDirectFunctionCall(expression) {
|
|
2253
|
+
if (!(expression instanceof Array)) return false;
|
|
2254
|
+
let [kind, _id, path, args] = expression;
|
|
2255
|
+
return kind === "pipeline" && expression.length === 4 && path instanceof Array && path.length === 0 && args instanceof Array;
|
|
2256
|
+
}
|
|
2252
2257
|
sendCall(id, path, args) {
|
|
2253
2258
|
if (this.abortReason) throw this.abortReason;
|
|
2254
2259
|
let value = ["pipeline", id, path];
|
|
@@ -2377,7 +2382,11 @@ var RpcSessionImpl = class {
|
|
|
2377
2382
|
let payload = new Evaluator(this).evaluate(msg[1]);
|
|
2378
2383
|
let hook = new PayloadStubHook(payload);
|
|
2379
2384
|
hook.ignoreUnhandledRejections();
|
|
2385
|
+
let exportId = this.exports.length;
|
|
2380
2386
|
this.exports.push({ hook, refcount: 1 });
|
|
2387
|
+
if (this.isDirectFunctionCall(msg[1])) {
|
|
2388
|
+
this.ensureResolvingExport(exportId);
|
|
2389
|
+
}
|
|
2381
2390
|
continue;
|
|
2382
2391
|
}
|
|
2383
2392
|
break;
|
|
@@ -2450,6 +2459,8 @@ var RpcSessionImpl = class {
|
|
|
2450
2459
|
throw new Error(`bad RPC message: ${JSON.stringify(msg)}`);
|
|
2451
2460
|
}
|
|
2452
2461
|
}
|
|
2462
|
+
// Use a fresh cancellation promise for each read. Reusing one session-long promise here causes
|
|
2463
|
+
// Promise.race() to accumulate reactions until the session is shut down.
|
|
2453
2464
|
receiveOrAbort() {
|
|
2454
2465
|
let readCanceled = Promise.withResolvers();
|
|
2455
2466
|
this.cancelReadLoop = readCanceled.reject;
|
|
@@ -2512,7 +2523,6 @@ var RpcSession = class {
|
|
|
2512
2523
|
};
|
|
2513
2524
|
|
|
2514
2525
|
// src/websocket.ts
|
|
2515
|
-
var RESOLVED_VOID_PROMISE = Promise.resolve();
|
|
2516
2526
|
function newWebSocketRpcSession(webSocket, localMain, options) {
|
|
2517
2527
|
if (typeof webSocket === "string") {
|
|
2518
2528
|
webSocket = new WebSocket(webSocket);
|
|
@@ -2577,23 +2587,18 @@ var WebSocketTransport = class {
|
|
|
2577
2587
|
#receiveRejecter;
|
|
2578
2588
|
#receiveQueue = [];
|
|
2579
2589
|
#error;
|
|
2580
|
-
send(message) {
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
this.#sendQueue.push(message);
|
|
2586
|
-
}
|
|
2587
|
-
return RESOLVED_VOID_PROMISE;
|
|
2588
|
-
} catch (err) {
|
|
2589
|
-
return Promise.reject(err);
|
|
2590
|
+
async send(message) {
|
|
2591
|
+
if (this.#sendQueue === void 0) {
|
|
2592
|
+
this.#webSocket.send(message);
|
|
2593
|
+
} else {
|
|
2594
|
+
this.#sendQueue.push(message);
|
|
2590
2595
|
}
|
|
2591
2596
|
}
|
|
2592
|
-
receive() {
|
|
2597
|
+
async receive() {
|
|
2593
2598
|
if (this.#receiveQueue.length > 0) {
|
|
2594
|
-
return
|
|
2599
|
+
return this.#receiveQueue.shift();
|
|
2595
2600
|
} else if (this.#error) {
|
|
2596
|
-
|
|
2601
|
+
throw this.#error;
|
|
2597
2602
|
} else {
|
|
2598
2603
|
return new Promise((resolve, reject) => {
|
|
2599
2604
|
this.#receiveResolver = resolve;
|
|
@@ -2626,7 +2631,6 @@ var WebSocketTransport = class {
|
|
|
2626
2631
|
};
|
|
2627
2632
|
|
|
2628
2633
|
// src/batch.ts
|
|
2629
|
-
var RESOLVED_VOID_PROMISE2 = Promise.resolve();
|
|
2630
2634
|
var BatchClientTransport = class {
|
|
2631
2635
|
constructor(sendBatch) {
|
|
2632
2636
|
this.#promise = this.#scheduleBatch(sendBatch);
|
|
@@ -2635,11 +2639,10 @@ var BatchClientTransport = class {
|
|
|
2635
2639
|
#aborted;
|
|
2636
2640
|
#batchToSend = [];
|
|
2637
2641
|
#batchToReceive = null;
|
|
2638
|
-
send(message) {
|
|
2642
|
+
async send(message) {
|
|
2639
2643
|
if (this.#batchToSend !== null) {
|
|
2640
2644
|
this.#batchToSend.push(message);
|
|
2641
2645
|
}
|
|
2642
|
-
return RESOLVED_VOID_PROMISE2;
|
|
2643
2646
|
}
|
|
2644
2647
|
async receive() {
|
|
2645
2648
|
if (!this.#batchToReceive) {
|
|
@@ -2689,9 +2692,8 @@ var BatchServerTransport = class {
|
|
|
2689
2692
|
#batchToSend = [];
|
|
2690
2693
|
#batchToReceive;
|
|
2691
2694
|
#allReceived = Promise.withResolvers();
|
|
2692
|
-
send(message) {
|
|
2695
|
+
async send(message) {
|
|
2693
2696
|
this.#batchToSend.push(message);
|
|
2694
|
-
return RESOLVED_VOID_PROMISE2;
|
|
2695
2697
|
}
|
|
2696
2698
|
async receive() {
|
|
2697
2699
|
let msg = this.#batchToReceive.shift();
|
|
@@ -2749,7 +2751,6 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
|
|
|
2749
2751
|
}
|
|
2750
2752
|
|
|
2751
2753
|
// src/messageport.ts
|
|
2752
|
-
var RESOLVED_VOID_PROMISE3 = Promise.resolve();
|
|
2753
2754
|
function newMessagePortRpcSession(port, localMain, options) {
|
|
2754
2755
|
let transport = new MessagePortTransport(port);
|
|
2755
2756
|
let rpc = new RpcSession(transport, localMain, options);
|
|
@@ -2783,22 +2784,17 @@ var MessagePortTransport = class {
|
|
|
2783
2784
|
#receiveRejecter;
|
|
2784
2785
|
#receiveQueue = [];
|
|
2785
2786
|
#error;
|
|
2786
|
-
send(message) {
|
|
2787
|
+
async send(message) {
|
|
2787
2788
|
if (this.#error) {
|
|
2788
|
-
|
|
2789
|
-
}
|
|
2790
|
-
try {
|
|
2791
|
-
this.#port.postMessage(message);
|
|
2792
|
-
return RESOLVED_VOID_PROMISE3;
|
|
2793
|
-
} catch (err) {
|
|
2794
|
-
return Promise.reject(err);
|
|
2789
|
+
throw this.#error;
|
|
2795
2790
|
}
|
|
2791
|
+
this.#port.postMessage(message);
|
|
2796
2792
|
}
|
|
2797
|
-
receive() {
|
|
2793
|
+
async receive() {
|
|
2798
2794
|
if (this.#receiveQueue.length > 0) {
|
|
2799
|
-
return
|
|
2795
|
+
return this.#receiveQueue.shift();
|
|
2800
2796
|
} else if (this.#error) {
|
|
2801
|
-
|
|
2797
|
+
throw this.#error;
|
|
2802
2798
|
} else {
|
|
2803
2799
|
return new Promise((resolve, reject) => {
|
|
2804
2800
|
this.#receiveResolver = resolve;
|