@vastblast/capnweb 0.7.4 → 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.
@@ -2271,6 +2271,11 @@ var RpcSessionImpl = class {
2271
2271
  this.transport.send(msgText).catch((err) => this.abort(err, false));
2272
2272
  return msgText.length;
2273
2273
  }
2274
+ isDirectFunctionCall(expression) {
2275
+ if (!(expression instanceof Array)) return false;
2276
+ let [kind, _id, path, args] = expression;
2277
+ return kind === "pipeline" && expression.length === 4 && path instanceof Array && path.length === 0 && args instanceof Array;
2278
+ }
2274
2279
  sendCall(id, path, args) {
2275
2280
  if (this.abortReason) throw this.abortReason;
2276
2281
  let value = ["pipeline", id, path];
@@ -2390,7 +2395,17 @@ var RpcSessionImpl = class {
2390
2395
  }
2391
2396
  async readLoop() {
2392
2397
  while (!this.abortReason) {
2393
- 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);
2394
2409
  if (this.abortReason) break;
2395
2410
  if (msg instanceof Array) {
2396
2411
  switch (msg[0]) {
@@ -2399,7 +2414,11 @@ var RpcSessionImpl = class {
2399
2414
  let payload = new Evaluator(this).evaluate(msg[1]);
2400
2415
  let hook = new PayloadStubHook(payload);
2401
2416
  hook.ignoreUnhandledRejections();
2417
+ let exportId = this.exports.length;
2402
2418
  this.exports.push({ hook, refcount: 1 });
2419
+ if (this.isDirectFunctionCall(msg[1])) {
2420
+ this.ensureResolvingExport(exportId);
2421
+ }
2403
2422
  continue;
2404
2423
  }
2405
2424
  break;
@@ -2472,24 +2491,6 @@ var RpcSessionImpl = class {
2472
2491
  throw new Error(`bad RPC message: ${JSON.stringify(msg)}`);
2473
2492
  }
2474
2493
  }
2475
- // Use a fresh cancellation promise for each read. Reusing one session-long promise here causes
2476
- // Promise.race() to accumulate reactions until the session is shut down.
2477
- receiveOrAbort() {
2478
- let readCanceled = Promise.withResolvers();
2479
- this.cancelReadLoop = readCanceled.reject;
2480
- let receivePromise;
2481
- try {
2482
- receivePromise = this.transport.receive();
2483
- } catch (err) {
2484
- this.cancelReadLoop = void 0;
2485
- return Promise.reject(err);
2486
- }
2487
- return Promise.race([receivePromise, readCanceled.promise]).finally(() => {
2488
- if (this.cancelReadLoop === readCanceled.reject) {
2489
- this.cancelReadLoop = void 0;
2490
- }
2491
- });
2492
- }
2493
2494
  async drain() {
2494
2495
  if (this.abortReason) {
2495
2496
  throw this.abortReason;