@vastblast/capnweb 0.7.0 → 0.7.1

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.
@@ -2045,14 +2045,17 @@ var RpcSessionImpl = class {
2045
2045
  this.options = options;
2046
2046
  this.exports.push({ hook: mainHook, refcount: 1 });
2047
2047
  this.imports.push(new ImportTableEntry(this, 0, false));
2048
+ this.cancelReadLoop = (error) => {
2049
+ this.activeReadAbort?.reject(error);
2050
+ };
2048
2051
  this.readLoop().catch((err) => this.abort(err));
2049
2052
  }
2050
2053
  exports = [];
2051
2054
  reverseExports = /* @__PURE__ */ new Map();
2052
2055
  imports = [];
2053
2056
  abortReason;
2054
- cancelReadLoop = () => {
2055
- };
2057
+ cancelReadLoop;
2058
+ activeReadAbort;
2056
2059
  // We assign positive numbers to imports we initiate, and negative numbers to exports we
2057
2060
  // initiate. So the next import ID is just `imports.length`, but the next export ID needs
2058
2061
  // to be tracked explicitly.
@@ -2368,17 +2371,15 @@ var RpcSessionImpl = class {
2368
2371
  }
2369
2372
  async readLoop() {
2370
2373
  while (!this.abortReason) {
2371
- let rejectFunc;
2372
- let abortPromise = new Promise((resolve, reject) => {
2373
- rejectFunc = reject;
2374
- });
2375
- this.cancelReadLoop = rejectFunc;
2374
+ let readAbort = Promise.withResolvers();
2375
+ this.activeReadAbort = readAbort;
2376
2376
  let msgText;
2377
2377
  try {
2378
- msgText = await Promise.race([this.transport.receive(), abortPromise]);
2378
+ msgText = await Promise.race([this.transport.receive(), readAbort.promise]);
2379
2379
  } finally {
2380
- this.cancelReadLoop = () => {
2381
- };
2380
+ if (this.activeReadAbort === readAbort) {
2381
+ this.activeReadAbort = void 0;
2382
+ }
2382
2383
  }
2383
2384
  let msg = JSON.parse(msgText);
2384
2385
  if (this.abortReason) break;