@fungi.computer/spore 0.4.0 → 0.6.0

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.
@@ -10280,6 +10280,7 @@ var ImportTableEntry = class {
10280
10280
  this.activePull.reject(error);
10281
10281
  this.activePull = void 0;
10282
10282
  }
10283
+ if (this.onBrokenRegistrations) for (let i of this.onBrokenRegistrations) delete this.session.onBrokenCallbacks[i];
10283
10284
  this.onBrokenRegistrations = void 0;
10284
10285
  }
10285
10286
  }
@@ -10437,6 +10438,7 @@ var RpcSessionImpl = class {
10437
10438
  refcount: 1
10438
10439
  };
10439
10440
  this.reverseExports.set(hook, exportId);
10441
+ this.watchExport(exportId, hook);
10440
10442
  return exportId;
10441
10443
  }
10442
10444
  }
@@ -10454,6 +10456,22 @@ var RpcSessionImpl = class {
10454
10456
  unexport(ids) {
10455
10457
  for (let id of ids) this.releaseExport(id, 1);
10456
10458
  }
10459
+ watchExport(exportId, hook) {
10460
+ hook.onBroken((error) => {
10461
+ queueMicrotask(() => {
10462
+ if (this.abortReason !== void 0 || this.exports[exportId]?.hook !== hook) return;
10463
+ try {
10464
+ this.send([
10465
+ "reject",
10466
+ exportId,
10467
+ Devaluator.devaluate(error, void 0, this, void 0, this.encodingLevel)
10468
+ ]);
10469
+ } catch (err) {
10470
+ this.abort(err);
10471
+ }
10472
+ });
10473
+ });
10474
+ }
10457
10475
  releaseExport(exportId, refcount) {
10458
10476
  let entry = this.exports[exportId];
10459
10477
  if (!entry) throw new Error(`no such export ID: ${exportId}`);
@@ -10720,8 +10738,8 @@ var RpcSessionImpl = class {
10720
10738
  } catch (err) {
10721
10739
  Promise.resolve(err);
10722
10740
  }
10723
- for (let i in this.onBrokenCallbacks) try {
10724
- this.onBrokenCallbacks[i](error);
10741
+ for (let callback of Object.values(this.onBrokenCallbacks)) try {
10742
+ callback(error);
10725
10743
  } catch (err) {
10726
10744
  Promise.resolve(err);
10727
10745
  }
@@ -10772,11 +10790,13 @@ var RpcSessionImpl = class {
10772
10790
  case "pipe": {
10773
10791
  let { readable, writable } = new TransformStream();
10774
10792
  let hook = streamImpl.createWritableStreamHook(writable);
10793
+ let exportId = this.exports.length;
10775
10794
  this.exports.push({
10776
10795
  hook,
10777
10796
  refcount: 1,
10778
10797
  pipeReadable: readable
10779
10798
  });
10799
+ this.watchExport(exportId, hook);
10780
10800
  continue;
10781
10801
  }
10782
10802
  case "pull": {
@@ -11279,6 +11299,7 @@ var WritableStreamStubHook = class WritableStreamStubHook2 extends StubHook {
11279
11299
  }
11280
11300
  }
11281
11301
  onBroken(callback) {
11302
+ this.getState().writer.closed.then(void 0, callback);
11282
11303
  }
11283
11304
  };
11284
11305
  var INITIAL_WINDOW = 262144;
@@ -11373,6 +11394,20 @@ function createWritableStreamFromHook(hook) {
11373
11394
  }
11374
11395
  };
11375
11396
  return new WritableStream({
11397
+ start(controller) {
11398
+ hook.onBroken((err) => {
11399
+ if (pendingError === void 0) {
11400
+ pendingError = err;
11401
+ controller.error(err);
11402
+ disposeHook();
11403
+ }
11404
+ if (windowReject) {
11405
+ windowReject(err);
11406
+ windowResolve = void 0;
11407
+ windowReject = void 0;
11408
+ }
11409
+ });
11410
+ },
11376
11411
  write(chunk, controller) {
11377
11412
  if (pendingError !== void 0) throw pendingError;
11378
11413
  const payload = RpcPayload.fromAppParams([chunk]);