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