@vastblast/capnweb 0.7.5 → 0.7.6

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.js CHANGED
@@ -2370,7 +2370,17 @@ var RpcSessionImpl = class {
2370
2370
  }
2371
2371
  async readLoop() {
2372
2372
  while (!this.abortReason) {
2373
- let msg = JSON.parse(await this.receiveOrAbort());
2373
+ let readCanceled = Promise.withResolvers();
2374
+ this.cancelReadLoop = readCanceled.reject;
2375
+ let msgText;
2376
+ try {
2377
+ msgText = await Promise.race([this.transport.receive(), readCanceled.promise]);
2378
+ } finally {
2379
+ if (this.cancelReadLoop === readCanceled.reject) {
2380
+ this.cancelReadLoop = void 0;
2381
+ }
2382
+ }
2383
+ let msg = JSON.parse(msgText);
2374
2384
  if (this.abortReason) break;
2375
2385
  if (msg instanceof Array) {
2376
2386
  switch (msg[0]) {
@@ -2456,24 +2466,6 @@ var RpcSessionImpl = class {
2456
2466
  throw new Error(`bad RPC message: ${JSON.stringify(msg)}`);
2457
2467
  }
2458
2468
  }
2459
- // Use a fresh cancellation promise for each read. Reusing one session-long promise here causes
2460
- // Promise.race() to accumulate reactions until the session is shut down.
2461
- receiveOrAbort() {
2462
- let readCanceled = Promise.withResolvers();
2463
- this.cancelReadLoop = readCanceled.reject;
2464
- let receivePromise;
2465
- try {
2466
- receivePromise = this.transport.receive();
2467
- } catch (err) {
2468
- this.cancelReadLoop = void 0;
2469
- return Promise.reject(err);
2470
- }
2471
- return Promise.race([receivePromise, readCanceled.promise]).finally(() => {
2472
- if (this.cancelReadLoop === readCanceled.reject) {
2473
- this.cancelReadLoop = void 0;
2474
- }
2475
- });
2476
- }
2477
2469
  async drain() {
2478
2470
  if (this.abortReason) {
2479
2471
  throw this.abortReason;