@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.
@@ -2395,7 +2395,17 @@ var RpcSessionImpl = class {
2395
2395
  }
2396
2396
  async readLoop() {
2397
2397
  while (!this.abortReason) {
2398
- let msg = JSON.parse(await this.receiveOrAbort());
2398
+ let readCanceled = Promise.withResolvers();
2399
+ this.cancelReadLoop = readCanceled.reject;
2400
+ let msgText;
2401
+ try {
2402
+ msgText = await Promise.race([this.transport.receive(), readCanceled.promise]);
2403
+ } finally {
2404
+ if (this.cancelReadLoop === readCanceled.reject) {
2405
+ this.cancelReadLoop = void 0;
2406
+ }
2407
+ }
2408
+ let msg = JSON.parse(msgText);
2399
2409
  if (this.abortReason) break;
2400
2410
  if (msg instanceof Array) {
2401
2411
  switch (msg[0]) {
@@ -2481,24 +2491,6 @@ var RpcSessionImpl = class {
2481
2491
  throw new Error(`bad RPC message: ${JSON.stringify(msg)}`);
2482
2492
  }
2483
2493
  }
2484
- // Use a fresh cancellation promise for each read. Reusing one session-long promise here causes
2485
- // Promise.race() to accumulate reactions until the session is shut down.
2486
- receiveOrAbort() {
2487
- let readCanceled = Promise.withResolvers();
2488
- this.cancelReadLoop = readCanceled.reject;
2489
- let receivePromise;
2490
- try {
2491
- receivePromise = this.transport.receive();
2492
- } catch (err) {
2493
- this.cancelReadLoop = void 0;
2494
- return Promise.reject(err);
2495
- }
2496
- return Promise.race([receivePromise, readCanceled.promise]).finally(() => {
2497
- if (this.cancelReadLoop === readCanceled.reject) {
2498
- this.cancelReadLoop = void 0;
2499
- }
2500
- });
2501
- }
2502
2494
  async drain() {
2503
2495
  if (this.abortReason) {
2504
2496
  throw this.abortReason;