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