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