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