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