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