@vastblast/capnweb 0.7.3 → 0.7.4
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 +18 -31
- package/dist/index-workers.cjs.map +1 -1
- package/dist/index-workers.js +18 -31
- package/dist/index-workers.js.map +1 -1
- package/dist/index.cjs +18 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2447,6 +2447,8 @@ var RpcSessionImpl = class {
|
|
|
2447
2447
|
throw new Error(`bad RPC message: ${JSON.stringify(msg)}`);
|
|
2448
2448
|
}
|
|
2449
2449
|
}
|
|
2450
|
+
// Use a fresh cancellation promise for each read. Reusing one session-long promise here causes
|
|
2451
|
+
// Promise.race() to accumulate reactions until the session is shut down.
|
|
2450
2452
|
receiveOrAbort() {
|
|
2451
2453
|
let readCanceled = Promise.withResolvers();
|
|
2452
2454
|
this.cancelReadLoop = readCanceled.reject;
|
|
@@ -2509,7 +2511,6 @@ var RpcSession = class {
|
|
|
2509
2511
|
};
|
|
2510
2512
|
|
|
2511
2513
|
// src/websocket.ts
|
|
2512
|
-
var RESOLVED_VOID_PROMISE = Promise.resolve();
|
|
2513
2514
|
function newWebSocketRpcSession(webSocket, localMain, options) {
|
|
2514
2515
|
if (typeof webSocket === "string") {
|
|
2515
2516
|
webSocket = new WebSocket(webSocket);
|
|
@@ -2574,23 +2575,18 @@ var WebSocketTransport = class {
|
|
|
2574
2575
|
#receiveRejecter;
|
|
2575
2576
|
#receiveQueue = [];
|
|
2576
2577
|
#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);
|
|
2578
|
+
async send(message) {
|
|
2579
|
+
if (this.#sendQueue === void 0) {
|
|
2580
|
+
this.#webSocket.send(message);
|
|
2581
|
+
} else {
|
|
2582
|
+
this.#sendQueue.push(message);
|
|
2587
2583
|
}
|
|
2588
2584
|
}
|
|
2589
|
-
receive() {
|
|
2585
|
+
async receive() {
|
|
2590
2586
|
if (this.#receiveQueue.length > 0) {
|
|
2591
|
-
return
|
|
2587
|
+
return this.#receiveQueue.shift();
|
|
2592
2588
|
} else if (this.#error) {
|
|
2593
|
-
|
|
2589
|
+
throw this.#error;
|
|
2594
2590
|
} else {
|
|
2595
2591
|
return new Promise((resolve, reject) => {
|
|
2596
2592
|
this.#receiveResolver = resolve;
|
|
@@ -2623,7 +2619,6 @@ var WebSocketTransport = class {
|
|
|
2623
2619
|
};
|
|
2624
2620
|
|
|
2625
2621
|
// src/batch.ts
|
|
2626
|
-
var RESOLVED_VOID_PROMISE2 = Promise.resolve();
|
|
2627
2622
|
var BatchClientTransport = class {
|
|
2628
2623
|
constructor(sendBatch) {
|
|
2629
2624
|
this.#promise = this.#scheduleBatch(sendBatch);
|
|
@@ -2632,11 +2627,10 @@ var BatchClientTransport = class {
|
|
|
2632
2627
|
#aborted;
|
|
2633
2628
|
#batchToSend = [];
|
|
2634
2629
|
#batchToReceive = null;
|
|
2635
|
-
send(message) {
|
|
2630
|
+
async send(message) {
|
|
2636
2631
|
if (this.#batchToSend !== null) {
|
|
2637
2632
|
this.#batchToSend.push(message);
|
|
2638
2633
|
}
|
|
2639
|
-
return RESOLVED_VOID_PROMISE2;
|
|
2640
2634
|
}
|
|
2641
2635
|
async receive() {
|
|
2642
2636
|
if (!this.#batchToReceive) {
|
|
@@ -2686,9 +2680,8 @@ var BatchServerTransport = class {
|
|
|
2686
2680
|
#batchToSend = [];
|
|
2687
2681
|
#batchToReceive;
|
|
2688
2682
|
#allReceived = Promise.withResolvers();
|
|
2689
|
-
send(message) {
|
|
2683
|
+
async send(message) {
|
|
2690
2684
|
this.#batchToSend.push(message);
|
|
2691
|
-
return RESOLVED_VOID_PROMISE2;
|
|
2692
2685
|
}
|
|
2693
2686
|
async receive() {
|
|
2694
2687
|
let msg = this.#batchToReceive.shift();
|
|
@@ -2746,7 +2739,6 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
|
|
|
2746
2739
|
}
|
|
2747
2740
|
|
|
2748
2741
|
// src/messageport.ts
|
|
2749
|
-
var RESOLVED_VOID_PROMISE3 = Promise.resolve();
|
|
2750
2742
|
function newMessagePortRpcSession(port, localMain, options) {
|
|
2751
2743
|
let transport = new MessagePortTransport(port);
|
|
2752
2744
|
let rpc = new RpcSession(transport, localMain, options);
|
|
@@ -2780,22 +2772,17 @@ var MessagePortTransport = class {
|
|
|
2780
2772
|
#receiveRejecter;
|
|
2781
2773
|
#receiveQueue = [];
|
|
2782
2774
|
#error;
|
|
2783
|
-
send(message) {
|
|
2775
|
+
async send(message) {
|
|
2784
2776
|
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);
|
|
2777
|
+
throw this.#error;
|
|
2792
2778
|
}
|
|
2779
|
+
this.#port.postMessage(message);
|
|
2793
2780
|
}
|
|
2794
|
-
receive() {
|
|
2781
|
+
async receive() {
|
|
2795
2782
|
if (this.#receiveQueue.length > 0) {
|
|
2796
|
-
return
|
|
2783
|
+
return this.#receiveQueue.shift();
|
|
2797
2784
|
} else if (this.#error) {
|
|
2798
|
-
|
|
2785
|
+
throw this.#error;
|
|
2799
2786
|
} else {
|
|
2800
2787
|
return new Promise((resolve, reject) => {
|
|
2801
2788
|
this.#receiveResolver = resolve;
|