@vastblast/capnweb 0.7.0 → 0.7.3
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 +51 -32
- package/dist/index-workers.cjs.map +1 -1
- package/dist/index-workers.js +51 -32
- package/dist/index-workers.js.map +1 -1
- package/dist/index.cjs +51 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2050,8 +2050,7 @@ var RpcSessionImpl = class {
|
|
|
2050
2050
|
reverseExports = /* @__PURE__ */ new Map();
|
|
2051
2051
|
imports = [];
|
|
2052
2052
|
abortReason;
|
|
2053
|
-
cancelReadLoop
|
|
2054
|
-
};
|
|
2053
|
+
cancelReadLoop;
|
|
2055
2054
|
// We assign positive numbers to imports we initiate, and negative numbers to exports we
|
|
2056
2055
|
// initiate. So the next import ID is just `imports.length`, but the next export ID needs
|
|
2057
2056
|
// to be tracked explicitly.
|
|
@@ -2329,7 +2328,8 @@ var RpcSessionImpl = class {
|
|
|
2329
2328
|
}
|
|
2330
2329
|
abort(error, trySendAbortMessage = true) {
|
|
2331
2330
|
if (this.abortReason !== void 0) return;
|
|
2332
|
-
this.cancelReadLoop(error);
|
|
2331
|
+
this.cancelReadLoop?.(error);
|
|
2332
|
+
this.cancelReadLoop = void 0;
|
|
2333
2333
|
if (trySendAbortMessage) {
|
|
2334
2334
|
try {
|
|
2335
2335
|
this.transport.send(JSON.stringify(["abort", Devaluator.devaluate(error, void 0, this)])).catch((err) => {
|
|
@@ -2367,19 +2367,7 @@ var RpcSessionImpl = class {
|
|
|
2367
2367
|
}
|
|
2368
2368
|
async readLoop() {
|
|
2369
2369
|
while (!this.abortReason) {
|
|
2370
|
-
let
|
|
2371
|
-
let abortPromise = new Promise((resolve, reject) => {
|
|
2372
|
-
rejectFunc = reject;
|
|
2373
|
-
});
|
|
2374
|
-
this.cancelReadLoop = rejectFunc;
|
|
2375
|
-
let msgText;
|
|
2376
|
-
try {
|
|
2377
|
-
msgText = await Promise.race([this.transport.receive(), abortPromise]);
|
|
2378
|
-
} finally {
|
|
2379
|
-
this.cancelReadLoop = () => {
|
|
2380
|
-
};
|
|
2381
|
-
}
|
|
2382
|
-
let msg = JSON.parse(msgText);
|
|
2370
|
+
let msg = JSON.parse(await this.receiveOrAbort());
|
|
2383
2371
|
if (this.abortReason) break;
|
|
2384
2372
|
if (msg instanceof Array) {
|
|
2385
2373
|
switch (msg[0]) {
|
|
@@ -2461,6 +2449,22 @@ var RpcSessionImpl = class {
|
|
|
2461
2449
|
throw new Error(`bad RPC message: ${JSON.stringify(msg)}`);
|
|
2462
2450
|
}
|
|
2463
2451
|
}
|
|
2452
|
+
receiveOrAbort() {
|
|
2453
|
+
let readCanceled = Promise.withResolvers();
|
|
2454
|
+
this.cancelReadLoop = readCanceled.reject;
|
|
2455
|
+
let receivePromise;
|
|
2456
|
+
try {
|
|
2457
|
+
receivePromise = this.transport.receive();
|
|
2458
|
+
} catch (err) {
|
|
2459
|
+
this.cancelReadLoop = void 0;
|
|
2460
|
+
return Promise.reject(err);
|
|
2461
|
+
}
|
|
2462
|
+
return Promise.race([receivePromise, readCanceled.promise]).finally(() => {
|
|
2463
|
+
if (this.cancelReadLoop === readCanceled.reject) {
|
|
2464
|
+
this.cancelReadLoop = void 0;
|
|
2465
|
+
}
|
|
2466
|
+
});
|
|
2467
|
+
}
|
|
2464
2468
|
async drain() {
|
|
2465
2469
|
if (this.abortReason) {
|
|
2466
2470
|
throw this.abortReason;
|
|
@@ -2507,6 +2511,7 @@ var RpcSession = class {
|
|
|
2507
2511
|
};
|
|
2508
2512
|
|
|
2509
2513
|
// src/websocket.ts
|
|
2514
|
+
var RESOLVED_VOID_PROMISE = Promise.resolve();
|
|
2510
2515
|
function newWebSocketRpcSession(webSocket, localMain, options) {
|
|
2511
2516
|
if (typeof webSocket === "string") {
|
|
2512
2517
|
webSocket = new WebSocket(webSocket);
|
|
@@ -2571,18 +2576,23 @@ var WebSocketTransport = class {
|
|
|
2571
2576
|
#receiveRejecter;
|
|
2572
2577
|
#receiveQueue = [];
|
|
2573
2578
|
#error;
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
this.#
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
+
send(message) {
|
|
2580
|
+
try {
|
|
2581
|
+
if (this.#sendQueue === void 0) {
|
|
2582
|
+
this.#webSocket.send(message);
|
|
2583
|
+
} else {
|
|
2584
|
+
this.#sendQueue.push(message);
|
|
2585
|
+
}
|
|
2586
|
+
return RESOLVED_VOID_PROMISE;
|
|
2587
|
+
} catch (err) {
|
|
2588
|
+
return Promise.reject(err);
|
|
2579
2589
|
}
|
|
2580
2590
|
}
|
|
2581
|
-
|
|
2591
|
+
receive() {
|
|
2582
2592
|
if (this.#receiveQueue.length > 0) {
|
|
2583
|
-
return this.#receiveQueue.shift();
|
|
2593
|
+
return Promise.resolve(this.#receiveQueue.shift());
|
|
2584
2594
|
} else if (this.#error) {
|
|
2585
|
-
|
|
2595
|
+
return Promise.reject(this.#error);
|
|
2586
2596
|
} else {
|
|
2587
2597
|
return new Promise((resolve, reject) => {
|
|
2588
2598
|
this.#receiveResolver = resolve;
|
|
@@ -2615,6 +2625,7 @@ var WebSocketTransport = class {
|
|
|
2615
2625
|
};
|
|
2616
2626
|
|
|
2617
2627
|
// src/batch.ts
|
|
2628
|
+
var RESOLVED_VOID_PROMISE2 = Promise.resolve();
|
|
2618
2629
|
var BatchClientTransport = class {
|
|
2619
2630
|
constructor(sendBatch) {
|
|
2620
2631
|
this.#promise = this.#scheduleBatch(sendBatch);
|
|
@@ -2623,10 +2634,11 @@ var BatchClientTransport = class {
|
|
|
2623
2634
|
#aborted;
|
|
2624
2635
|
#batchToSend = [];
|
|
2625
2636
|
#batchToReceive = null;
|
|
2626
|
-
|
|
2637
|
+
send(message) {
|
|
2627
2638
|
if (this.#batchToSend !== null) {
|
|
2628
2639
|
this.#batchToSend.push(message);
|
|
2629
2640
|
}
|
|
2641
|
+
return RESOLVED_VOID_PROMISE2;
|
|
2630
2642
|
}
|
|
2631
2643
|
async receive() {
|
|
2632
2644
|
if (!this.#batchToReceive) {
|
|
@@ -2676,8 +2688,9 @@ var BatchServerTransport = class {
|
|
|
2676
2688
|
#batchToSend = [];
|
|
2677
2689
|
#batchToReceive;
|
|
2678
2690
|
#allReceived = Promise.withResolvers();
|
|
2679
|
-
|
|
2691
|
+
send(message) {
|
|
2680
2692
|
this.#batchToSend.push(message);
|
|
2693
|
+
return RESOLVED_VOID_PROMISE2;
|
|
2681
2694
|
}
|
|
2682
2695
|
async receive() {
|
|
2683
2696
|
let msg = this.#batchToReceive.shift();
|
|
@@ -2735,6 +2748,7 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
|
|
|
2735
2748
|
}
|
|
2736
2749
|
|
|
2737
2750
|
// src/messageport.ts
|
|
2751
|
+
var RESOLVED_VOID_PROMISE3 = Promise.resolve();
|
|
2738
2752
|
function newMessagePortRpcSession(port, localMain, options) {
|
|
2739
2753
|
let transport = new MessagePortTransport(port);
|
|
2740
2754
|
let rpc = new RpcSession(transport, localMain, options);
|
|
@@ -2768,17 +2782,22 @@ var MessagePortTransport = class {
|
|
|
2768
2782
|
#receiveRejecter;
|
|
2769
2783
|
#receiveQueue = [];
|
|
2770
2784
|
#error;
|
|
2771
|
-
|
|
2785
|
+
send(message) {
|
|
2772
2786
|
if (this.#error) {
|
|
2773
|
-
|
|
2787
|
+
return Promise.reject(this.#error);
|
|
2788
|
+
}
|
|
2789
|
+
try {
|
|
2790
|
+
this.#port.postMessage(message);
|
|
2791
|
+
return RESOLVED_VOID_PROMISE3;
|
|
2792
|
+
} catch (err) {
|
|
2793
|
+
return Promise.reject(err);
|
|
2774
2794
|
}
|
|
2775
|
-
this.#port.postMessage(message);
|
|
2776
2795
|
}
|
|
2777
|
-
|
|
2796
|
+
receive() {
|
|
2778
2797
|
if (this.#receiveQueue.length > 0) {
|
|
2779
|
-
return this.#receiveQueue.shift();
|
|
2798
|
+
return Promise.resolve(this.#receiveQueue.shift());
|
|
2780
2799
|
} else if (this.#error) {
|
|
2781
|
-
|
|
2800
|
+
return Promise.reject(this.#error);
|
|
2782
2801
|
} else {
|
|
2783
2802
|
return new Promise((resolve, reject) => {
|
|
2784
2803
|
this.#receiveResolver = resolve;
|