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