@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.
package/dist/index.js CHANGED
@@ -2246,6 +2246,11 @@ var RpcSessionImpl = class {
2246
2246
  this.transport.send(msgText).catch((err) => this.abort(err, false));
2247
2247
  return msgText.length;
2248
2248
  }
2249
+ isDirectFunctionCall(expression) {
2250
+ if (!(expression instanceof Array)) return false;
2251
+ let [kind, _id, path, args] = expression;
2252
+ return kind === "pipeline" && expression.length === 4 && path instanceof Array && path.length === 0 && args instanceof Array;
2253
+ }
2249
2254
  sendCall(id, path, args) {
2250
2255
  if (this.abortReason) throw this.abortReason;
2251
2256
  let value = ["pipeline", id, path];
@@ -2365,7 +2370,17 @@ var RpcSessionImpl = class {
2365
2370
  }
2366
2371
  async readLoop() {
2367
2372
  while (!this.abortReason) {
2368
- let msg = JSON.parse(await this.receiveOrAbort());
2373
+ let readCanceled = Promise.withResolvers();
2374
+ this.cancelReadLoop = readCanceled.reject;
2375
+ let msgText;
2376
+ try {
2377
+ msgText = await Promise.race([this.transport.receive(), readCanceled.promise]);
2378
+ } finally {
2379
+ if (this.cancelReadLoop === readCanceled.reject) {
2380
+ this.cancelReadLoop = void 0;
2381
+ }
2382
+ }
2383
+ let msg = JSON.parse(msgText);
2369
2384
  if (this.abortReason) break;
2370
2385
  if (msg instanceof Array) {
2371
2386
  switch (msg[0]) {
@@ -2374,7 +2389,11 @@ var RpcSessionImpl = class {
2374
2389
  let payload = new Evaluator(this).evaluate(msg[1]);
2375
2390
  let hook = new PayloadStubHook(payload);
2376
2391
  hook.ignoreUnhandledRejections();
2392
+ let exportId = this.exports.length;
2377
2393
  this.exports.push({ hook, refcount: 1 });
2394
+ if (this.isDirectFunctionCall(msg[1])) {
2395
+ this.ensureResolvingExport(exportId);
2396
+ }
2378
2397
  continue;
2379
2398
  }
2380
2399
  break;
@@ -2447,24 +2466,6 @@ var RpcSessionImpl = class {
2447
2466
  throw new Error(`bad RPC message: ${JSON.stringify(msg)}`);
2448
2467
  }
2449
2468
  }
2450
- // Use a fresh cancellation promise for each read. Reusing one session-long promise here causes
2451
- // Promise.race() to accumulate reactions until the session is shut down.
2452
- receiveOrAbort() {
2453
- let readCanceled = Promise.withResolvers();
2454
- this.cancelReadLoop = readCanceled.reject;
2455
- let receivePromise;
2456
- try {
2457
- receivePromise = this.transport.receive();
2458
- } catch (err) {
2459
- this.cancelReadLoop = void 0;
2460
- return Promise.reject(err);
2461
- }
2462
- return Promise.race([receivePromise, readCanceled.promise]).finally(() => {
2463
- if (this.cancelReadLoop === readCanceled.reject) {
2464
- this.cancelReadLoop = void 0;
2465
- }
2466
- });
2467
- }
2468
2469
  async drain() {
2469
2470
  if (this.abortReason) {
2470
2471
  throw this.abortReason;