brass-runtime 1.17.0 → 1.18.1
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/README.md +36 -3
- package/dist/agent/cli/main.cjs +31 -32
- package/dist/agent/cli/main.js +3 -4
- package/dist/agent/cli/main.mjs +3 -4
- package/dist/agent/index.cjs +4 -5
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +3 -4
- package/dist/agent/index.mjs +3 -4
- package/dist/{chunk-7X3K5RMS.js → chunk-22HZQG5F.js} +9 -11
- package/dist/{chunk-GLE2WY7Z.cjs → chunk-2JHJ4YHS.cjs} +417 -124
- package/dist/{chunk-Q2I37RP3.cjs → chunk-2OW6IFY2.cjs} +44 -323
- package/dist/{chunk-7ZPEZ57L.cjs → chunk-5LC7V2OZ.cjs} +18 -20
- package/dist/{chunk-AGR5B2BC.cjs → chunk-5RZ7YITF.cjs} +564 -12
- package/dist/{chunk-DNFJLJMW.mjs → chunk-6MLAZPBL.mjs} +48 -24
- package/dist/{chunk-EJ6BPYVR.mjs → chunk-6V2AWT4R.mjs} +1 -1
- package/dist/{chunk-3AYM6WPJ.js → chunk-7DU7IQHK.js} +20 -299
- package/dist/{chunk-SK7UZRNI.mjs → chunk-7GBJYOX7.mjs} +528 -23
- package/dist/chunk-7TKI527D.cjs +123 -0
- package/dist/{chunk-52OB2ROS.js → chunk-7VQLEN37.js} +2 -4
- package/dist/{chunk-KH4SYAOS.mjs → chunk-B5FKOLTB.mjs} +20 -299
- package/dist/{chunk-FHQGHPMO.mjs → chunk-BC6Q6BCO.mjs} +2 -4
- package/dist/{chunk-4P2HHGAX.mjs → chunk-COOW7BJX.mjs} +32 -11
- package/dist/{chunk-2HQTDLHF.mjs → chunk-EEN5OTCR.mjs} +555 -3
- package/dist/{chunk-KZJQ723N.cjs → chunk-EICAJDNX.cjs} +13 -15
- package/dist/chunk-ELIECDYN.cjs +33 -0
- package/dist/{chunk-GYM3LLGS.mjs → chunk-H626ZTDZ.mjs} +399 -106
- package/dist/{chunk-C3MDXTRZ.js → chunk-HCJ4S3YB.js} +48 -24
- package/dist/{chunk-7JIJOVCT.js → chunk-IPSMXUWA.js} +2 -4
- package/dist/{chunk-4ROBZFL6.cjs → chunk-J6DUHITE.cjs} +6 -8
- package/dist/{chunk-6RY2FFN4.mjs → chunk-JWIEMBE6.mjs} +9 -11
- package/dist/{chunk-PD4EJTQC.cjs → chunk-KNTJ7FQB.cjs} +5 -5
- package/dist/chunk-KTGDLBLD.mjs +123 -0
- package/dist/chunk-LSYQ3C2M.js +33 -0
- package/dist/{chunk-RKGKFN2A.js → chunk-OW5VHAOE.js} +1 -1
- package/dist/{chunk-EOC4UHBS.mjs → chunk-RBHNOKH4.mjs} +2 -2
- package/dist/{chunk-6IXXWIUM.js → chunk-S4HXADU4.js} +555 -3
- package/dist/{chunk-FH2X7BVP.js → chunk-TTSPIU3U.js} +399 -106
- package/dist/{chunk-5QC7LRZ3.js → chunk-UAKAF32U.js} +2 -2
- package/dist/{chunk-CZIVE6NT.cjs → chunk-UUMKZJRJ.cjs} +48 -24
- package/dist/{chunk-MBEJI5HF.mjs → chunk-WCBNXPN6.mjs} +2 -4
- package/dist/{chunk-52PPNNI4.cjs → chunk-WGE2FEZE.cjs} +2 -2
- package/dist/{chunk-WBGRHGBP.cjs → chunk-WI7GZF3B.cjs} +114 -93
- package/dist/chunk-WUDHOZIH.js +6234 -0
- package/dist/{chunk-F6XWZQY4.cjs → chunk-WVSZOPGQ.cjs} +583 -78
- package/dist/chunk-XPIMJQYS.cjs +6234 -0
- package/dist/{chunk-VWIPB6I5.js → chunk-YGR2IN4R.js} +528 -23
- package/dist/chunk-YM3EDNYD.js +123 -0
- package/dist/chunk-YWLLH27R.mjs +33 -0
- package/dist/{chunk-BKK77SBA.js → chunk-YZ5LQ32F.js} +32 -11
- package/dist/chunk-Z3ZZMQUZ.mjs +6234 -0
- package/dist/core/index.cjs +37 -9
- package/dist/core/index.d.ts +19 -152
- package/dist/core/index.js +86 -58
- package/dist/core/index.mjs +86 -58
- package/dist/defaultClient-Cid0JoUR.d.ts +1648 -0
- package/dist/{effect-DIUHZ9IN.d.ts → effect-DnGUuhw6.d.ts} +22 -1
- package/dist/http/index.cjs +206 -59
- package/dist/http/index.d.ts +55 -819
- package/dist/http/index.js +220 -73
- package/dist/http/index.mjs +220 -73
- package/dist/http/testing.cjs +31 -10
- package/dist/http/testing.d.ts +16 -5
- package/dist/http/testing.js +29 -8
- package/dist/http/testing.mjs +29 -8
- package/dist/index.cjs +116 -88
- package/dist/index.d.ts +9 -8
- package/dist/index.js +87 -59
- package/dist/index.mjs +87 -59
- package/dist/{schedule-CK3Ml_7p.d.ts → layer-D2LFcBVx.d.ts} +176 -2
- package/dist/observability/index.cjs +20 -7
- package/dist/observability/index.d.ts +32 -8
- package/dist/observability/index.js +19 -6
- package/dist/observability/index.mjs +19 -6
- package/dist/perf/cli.cjs +26 -28
- package/dist/perf/cli.js +11 -13
- package/dist/perf/cli.mjs +11 -13
- package/dist/perf/index.cjs +13 -15
- package/dist/perf/index.js +11 -13
- package/dist/perf/index.mjs +11 -13
- package/dist/schema/index.cjs +2 -2
- package/dist/schema/index.js +1 -1
- package/dist/schema/index.mjs +1 -1
- package/dist/{server-D6JZ15_e.d.ts → server-Bf1zNYZk.d.ts} +5 -5
- package/dist/{stream-B4oK9JFP.d.ts → stream-I7bkvF7a.d.ts} +1 -1
- package/dist/{tracer-Hwt1cl7h.d.ts → tracer-DF83nLn6.d.ts} +2 -2
- package/dist/{tracing-DqbTKGcf.d.ts → tracing-CWV4gT0u.d.ts} +1 -1
- package/docs/README.md +2 -0
- package/docs/ai/PUBLIC_API.md +28 -7
- package/docs/articles/brass-runtime-http-observability.md +467 -0
- package/docs/frameworks/angular.md +51 -0
- package/docs/frameworks/express.md +58 -0
- package/docs/frameworks/fastify.md +49 -0
- package/docs/frameworks/nestjs.md +53 -0
- package/docs/frameworks/nextjs.md +55 -0
- package/docs/frameworks/react.md +44 -0
- package/docs/frameworks/vanilla.md +56 -0
- package/docs/guides/layers.md +130 -0
- package/docs/http-recipes.md +31 -1
- package/docs/http.md +50 -1
- package/docs/observability.md +132 -0
- package/docs/performance-profiler.md +6 -2
- package/docs/recipes/layers.md +46 -2
- package/docs/recipes/testing.md +25 -0
- package/package.json +6 -2
- package/dist/chunk-3LOYJFRR.cjs +0 -300
- package/dist/chunk-3Y2RIUMM.js +0 -300
- package/dist/chunk-5EC274J5.cjs +0 -2874
- package/dist/chunk-5VRJNBLZ.mjs +0 -2874
- package/dist/chunk-62AZW6UT.cjs +0 -313
- package/dist/chunk-74ZTY6CP.js +0 -2871
- package/dist/chunk-7CMJS3QE.mjs +0 -2871
- package/dist/chunk-A2OM6NEH.mjs +0 -194
- package/dist/chunk-B33ICAKP.js +0 -313
- package/dist/chunk-JF5WGYJJ.cjs +0 -194
- package/dist/chunk-KN32XNTH.mjs +0 -313
- package/dist/chunk-KQLYONSE.cjs +0 -2871
- package/dist/chunk-L2SYFEBS.js +0 -194
- package/dist/chunk-MIIYDLGM.js +0 -2874
- package/dist/chunk-PWC3RBQE.mjs +0 -300
- package/dist/client-CZHU674n.d.ts +0 -820
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
2
5
|
|
|
3
6
|
|
|
4
7
|
|
|
@@ -7,7 +10,7 @@ var _chunkMVGUEJ5Zcjs = require('./chunk-MVGUEJ5Z.cjs');
|
|
|
7
10
|
|
|
8
11
|
|
|
9
12
|
|
|
10
|
-
var
|
|
13
|
+
var _chunkUUMKZJRJcjs = require('./chunk-UUMKZJRJ.cjs');
|
|
11
14
|
|
|
12
15
|
// src/core/runtime/ringBuffer.ts
|
|
13
16
|
var PushStatus = /* @__PURE__ */ ((PushStatus3) => {
|
|
@@ -2824,11 +2827,11 @@ function normalizeRuntimeEngineMode(value) {
|
|
|
2824
2827
|
function unreachableEngine(value) {
|
|
2825
2828
|
throw new Error(`brass-runtime unsupported engine '${String(value)}'`);
|
|
2826
2829
|
}
|
|
2827
|
-
var runtimeOptionsSchema =
|
|
2828
|
-
env:
|
|
2829
|
-
lane:
|
|
2830
|
-
inferLane:
|
|
2831
|
-
engine:
|
|
2830
|
+
var runtimeOptionsSchema = _chunkUUMKZJRJcjs.Schema.object({
|
|
2831
|
+
env: _chunkUUMKZJRJcjs.Schema.any(),
|
|
2832
|
+
lane: _chunkUUMKZJRJcjs.Schema.string({ minLength: 1 }).optional(),
|
|
2833
|
+
inferLane: _chunkUUMKZJRJcjs.Schema.boolean().optional(),
|
|
2834
|
+
engine: _chunkUUMKZJRJcjs.Schema.enum(["ts", "wasm"]).optional()
|
|
2832
2835
|
}, { unknownKeys: "passthrough" });
|
|
2833
2836
|
var Runtime = class _Runtime {
|
|
2834
2837
|
|
|
@@ -2845,7 +2848,7 @@ var Runtime = class _Runtime {
|
|
|
2845
2848
|
// opcional: registry para observabilidad
|
|
2846
2849
|
|
|
2847
2850
|
constructor(args) {
|
|
2848
|
-
|
|
2851
|
+
_chunkUUMKZJRJcjs.parseConfig.call(void 0, "RuntimeOptions", runtimeOptionsSchema, args);
|
|
2849
2852
|
this.env = args.env;
|
|
2850
2853
|
this.scheduler = _nullishCoalesce(args.scheduler, () => ( globalScheduler));
|
|
2851
2854
|
this.lane = args.lane;
|
|
@@ -2947,38 +2950,50 @@ var Runtime = class _Runtime {
|
|
|
2947
2950
|
const fiber = this.fork(effect);
|
|
2948
2951
|
fiber.join(cb);
|
|
2949
2952
|
}
|
|
2953
|
+
static exitToError(exit) {
|
|
2954
|
+
if (exit._tag === "Success") return void 0;
|
|
2955
|
+
const failure = _chunkMVGUEJ5Zcjs.Cause.firstFailure(exit.cause);
|
|
2956
|
+
if (failure._tag === "Some") return failure.value;
|
|
2957
|
+
const defect = _chunkMVGUEJ5Zcjs.Cause.firstDefect(exit.cause);
|
|
2958
|
+
if (defect._tag === "Some") {
|
|
2959
|
+
return defect.value instanceof Error ? defect.value : new Error(String(defect.value));
|
|
2960
|
+
}
|
|
2961
|
+
if (_chunkMVGUEJ5Zcjs.Cause.containsInterrupt(exit.cause)) return new Error("Interrupted");
|
|
2962
|
+
return _chunkMVGUEJ5Zcjs.Cause.toError(exit.cause);
|
|
2963
|
+
}
|
|
2950
2964
|
toPromise(effect) {
|
|
2965
|
+
let syncExit;
|
|
2966
|
+
let promiseResolve;
|
|
2967
|
+
let promiseReject;
|
|
2968
|
+
const complete = (exit) => {
|
|
2969
|
+
if (promiseResolve) {
|
|
2970
|
+
if (exit._tag === "Success") promiseResolve(exit.value);
|
|
2971
|
+
else promiseReject(_Runtime.exitToError(exit));
|
|
2972
|
+
} else {
|
|
2973
|
+
syncExit = exit;
|
|
2974
|
+
}
|
|
2975
|
+
};
|
|
2976
|
+
if (this.tryRunNativeTopLevel(effect, complete)) {
|
|
2977
|
+
if (syncExit) {
|
|
2978
|
+
return syncExit._tag === "Success" ? Promise.resolve(syncExit.value) : Promise.reject(_Runtime.exitToError(syncExit));
|
|
2979
|
+
}
|
|
2980
|
+
return new Promise((resolve, reject) => {
|
|
2981
|
+
promiseResolve = resolve;
|
|
2982
|
+
promiseReject = reject;
|
|
2983
|
+
});
|
|
2984
|
+
}
|
|
2951
2985
|
return new Promise((resolve, reject) => {
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
resolve(exit.value);
|
|
2955
|
-
return;
|
|
2956
|
-
}
|
|
2957
|
-
const failure = _chunkMVGUEJ5Zcjs.Cause.firstFailure(exit.cause);
|
|
2958
|
-
if (failure._tag === "Some") reject(failure.value);
|
|
2959
|
-
else {
|
|
2960
|
-
const defect = _chunkMVGUEJ5Zcjs.Cause.firstDefect(exit.cause);
|
|
2961
|
-
if (defect._tag === "Some") {
|
|
2962
|
-
reject(defect.value instanceof Error ? defect.value : new Error(String(defect.value)));
|
|
2963
|
-
} else if (_chunkMVGUEJ5Zcjs.Cause.containsInterrupt(exit.cause)) {
|
|
2964
|
-
reject(new Error("Interrupted"));
|
|
2965
|
-
} else {
|
|
2966
|
-
reject(_chunkMVGUEJ5Zcjs.Cause.toError(exit.cause));
|
|
2967
|
-
}
|
|
2968
|
-
}
|
|
2969
|
-
};
|
|
2970
|
-
if (this.tryRunNativeTopLevel(effect, complete)) return;
|
|
2986
|
+
promiseResolve = resolve;
|
|
2987
|
+
promiseReject = reject;
|
|
2971
2988
|
const fiber = this.fork(effect);
|
|
2972
|
-
fiber.join(
|
|
2973
|
-
complete(exit);
|
|
2974
|
-
});
|
|
2989
|
+
fiber.join(complete);
|
|
2975
2990
|
});
|
|
2976
2991
|
}
|
|
2977
2992
|
tryRunNativeTopLevel(effect, cb) {
|
|
2978
2993
|
if (this.hooks !== NoopHooks) return false;
|
|
2979
2994
|
if (getCurrentFiber() !== null) return false;
|
|
2980
2995
|
if (this.scheduler !== globalScheduler) return false;
|
|
2981
|
-
if (this.
|
|
2996
|
+
if (this.inferLane) return false;
|
|
2982
2997
|
if (this.engineMode !== "ts") return false;
|
|
2983
2998
|
new NativeTopLevelRunner(this, effect, cb).start();
|
|
2984
2999
|
return true;
|
|
@@ -3137,7 +3152,7 @@ var NativeTopLevelRunner = (_class16 = class {
|
|
|
3137
3152
|
syncExit = exit;
|
|
3138
3153
|
return;
|
|
3139
3154
|
}
|
|
3140
|
-
|
|
3155
|
+
this.resumeAsync(exit);
|
|
3141
3156
|
};
|
|
3142
3157
|
try {
|
|
3143
3158
|
current.register(this.runtime.env, resume);
|
|
@@ -3271,6 +3286,12 @@ var abortablePromiseTotals = {
|
|
|
3271
3286
|
lateSettlements: 0
|
|
3272
3287
|
};
|
|
3273
3288
|
var abortablePromiseLabels = /* @__PURE__ */ new Map();
|
|
3289
|
+
var perLabelTrackingEnabled = false;
|
|
3290
|
+
function setAbortablePromisePerLabelTracking(enabled) {
|
|
3291
|
+
const previous = perLabelTrackingEnabled;
|
|
3292
|
+
perLabelTrackingEnabled = enabled;
|
|
3293
|
+
return previous;
|
|
3294
|
+
}
|
|
3274
3295
|
var getAbortablePromiseLabelStats = (label) => {
|
|
3275
3296
|
const existing = abortablePromiseLabels.get(label);
|
|
3276
3297
|
if (existing) return existing;
|
|
@@ -3288,44 +3309,60 @@ var getAbortablePromiseLabelStats = (label) => {
|
|
|
3288
3309
|
return created;
|
|
3289
3310
|
};
|
|
3290
3311
|
var recordAbortablePromiseStart = (label) => {
|
|
3291
|
-
const byLabel = getAbortablePromiseLabelStats(label);
|
|
3292
3312
|
abortablePromiseTotals.active++;
|
|
3293
3313
|
abortablePromiseTotals.started++;
|
|
3294
|
-
|
|
3295
|
-
|
|
3314
|
+
if (perLabelTrackingEnabled) {
|
|
3315
|
+
const byLabel = getAbortablePromiseLabelStats(label);
|
|
3316
|
+
byLabel.active++;
|
|
3317
|
+
byLabel.started++;
|
|
3318
|
+
}
|
|
3296
3319
|
};
|
|
3297
3320
|
var recordAbortablePromiseFinish = (label, outcome) => {
|
|
3298
|
-
const byLabel = getAbortablePromiseLabelStats(label);
|
|
3299
3321
|
if (abortablePromiseTotals.active > 0) abortablePromiseTotals.active--;
|
|
3300
|
-
if (byLabel.active > 0) byLabel.active--;
|
|
3301
3322
|
switch (outcome) {
|
|
3302
3323
|
case "success":
|
|
3303
3324
|
abortablePromiseTotals.succeeded++;
|
|
3304
|
-
|
|
3305
|
-
return;
|
|
3325
|
+
break;
|
|
3306
3326
|
case "failure":
|
|
3307
3327
|
abortablePromiseTotals.failed++;
|
|
3308
|
-
|
|
3309
|
-
return;
|
|
3328
|
+
break;
|
|
3310
3329
|
case "interrupt":
|
|
3311
3330
|
abortablePromiseTotals.interrupted++;
|
|
3312
|
-
|
|
3313
|
-
return;
|
|
3331
|
+
break;
|
|
3314
3332
|
case "timeout":
|
|
3315
3333
|
abortablePromiseTotals.timedOut++;
|
|
3316
|
-
|
|
3317
|
-
|
|
3334
|
+
break;
|
|
3335
|
+
}
|
|
3336
|
+
if (perLabelTrackingEnabled) {
|
|
3337
|
+
const byLabel = getAbortablePromiseLabelStats(label);
|
|
3338
|
+
if (byLabel.active > 0) byLabel.active--;
|
|
3339
|
+
switch (outcome) {
|
|
3340
|
+
case "success":
|
|
3341
|
+
byLabel.succeeded++;
|
|
3342
|
+
return;
|
|
3343
|
+
case "failure":
|
|
3344
|
+
byLabel.failed++;
|
|
3345
|
+
return;
|
|
3346
|
+
case "interrupt":
|
|
3347
|
+
byLabel.interrupted++;
|
|
3348
|
+
return;
|
|
3349
|
+
case "timeout":
|
|
3350
|
+
byLabel.timedOut++;
|
|
3351
|
+
return;
|
|
3352
|
+
}
|
|
3318
3353
|
}
|
|
3319
3354
|
};
|
|
3320
3355
|
var recordAbortablePromiseLateSettlement = (label) => {
|
|
3321
|
-
const byLabel = getAbortablePromiseLabelStats(label);
|
|
3322
3356
|
abortablePromiseTotals.lateSettlements++;
|
|
3323
|
-
|
|
3357
|
+
if (perLabelTrackingEnabled) {
|
|
3358
|
+
const byLabel = getAbortablePromiseLabelStats(label);
|
|
3359
|
+
byLabel.lateSettlements++;
|
|
3360
|
+
}
|
|
3324
3361
|
};
|
|
3325
3362
|
function abortablePromiseStats() {
|
|
3326
3363
|
return {
|
|
3327
3364
|
...abortablePromiseTotals,
|
|
3328
|
-
byLabel: Array.from(abortablePromiseLabels.values()).map((x) => ({ ...x })).sort((a, b) => b.active - a.active || b.started - a.started || a.label.localeCompare(b.label))
|
|
3365
|
+
byLabel: perLabelTrackingEnabled ? Array.from(abortablePromiseLabels.values()).map((x) => ({ ...x })).sort((a, b) => b.active - a.active || b.started - a.started || a.label.localeCompare(b.label)) : []
|
|
3329
3366
|
};
|
|
3330
3367
|
}
|
|
3331
3368
|
function resetAbortablePromiseStats() {
|
|
@@ -3347,76 +3384,149 @@ var makeTimeoutReason = (timeoutMs, label) => ({
|
|
|
3347
3384
|
timeoutMs,
|
|
3348
3385
|
message: `Abortable promise '${label}' timed out after ${timeoutMs}ms`
|
|
3349
3386
|
});
|
|
3387
|
+
function registerWithTimeout(make, onReject, options, env, cb, timeoutMs) {
|
|
3388
|
+
const controller = new AbortController();
|
|
3389
|
+
const label = normalizeAbortablePromiseLabel(options.label);
|
|
3390
|
+
const startedAt = performance.now();
|
|
3391
|
+
let done = false;
|
|
3392
|
+
let cleanup;
|
|
3393
|
+
const hasHooks = options.onStart !== void 0 || options.onFinish !== void 0;
|
|
3394
|
+
const finish = hasHooks ? (outcome, exit, error) => {
|
|
3395
|
+
if (done) return;
|
|
3396
|
+
done = true;
|
|
3397
|
+
cleanup();
|
|
3398
|
+
recordAbortablePromiseFinish(label, outcome);
|
|
3399
|
+
_optionalChain([options, 'access', _189 => _189.onFinish, 'optionalCall', _190 => _190({
|
|
3400
|
+
label,
|
|
3401
|
+
outcome,
|
|
3402
|
+
durationMs: Math.round(performance.now() - startedAt),
|
|
3403
|
+
error
|
|
3404
|
+
})]);
|
|
3405
|
+
cb(exit);
|
|
3406
|
+
} : (outcome, exit, _error) => {
|
|
3407
|
+
if (done) return;
|
|
3408
|
+
done = true;
|
|
3409
|
+
cleanup();
|
|
3410
|
+
recordAbortablePromiseFinish(label, outcome);
|
|
3411
|
+
cb(exit);
|
|
3412
|
+
};
|
|
3413
|
+
recordAbortablePromiseStart(label);
|
|
3414
|
+
if (hasHooks) _optionalChain([options, 'access', _191 => _191.onStart, 'optionalCall', _192 => _192(label)]);
|
|
3415
|
+
const onTimeout = () => {
|
|
3416
|
+
const reason = _nullishCoalesce(_optionalChain([options, 'access', _193 => _193.timeoutReason, 'optionalCall', _194 => _194()]), () => ( makeTimeoutReason(timeoutMs, label)));
|
|
3417
|
+
try {
|
|
3418
|
+
controller.abort(reason);
|
|
3419
|
+
} catch (e10) {
|
|
3420
|
+
controller.abort();
|
|
3421
|
+
}
|
|
3422
|
+
finish("timeout", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(reason))), reason);
|
|
3423
|
+
};
|
|
3424
|
+
if (options.timerWheel) {
|
|
3425
|
+
const handle = options.timerWheel.schedule(timeoutMs, onTimeout);
|
|
3426
|
+
cleanup = () => {
|
|
3427
|
+
handle.cancel();
|
|
3428
|
+
};
|
|
3429
|
+
} else {
|
|
3430
|
+
let timeoutHandle = setTimeout(onTimeout, timeoutMs);
|
|
3431
|
+
cleanup = () => {
|
|
3432
|
+
if (timeoutHandle !== void 0) {
|
|
3433
|
+
clearTimeout(timeoutHandle);
|
|
3434
|
+
timeoutHandle = void 0;
|
|
3435
|
+
}
|
|
3436
|
+
};
|
|
3437
|
+
}
|
|
3438
|
+
let promise;
|
|
3439
|
+
try {
|
|
3440
|
+
promise = make(controller.signal, env);
|
|
3441
|
+
} catch (err) {
|
|
3442
|
+
finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
|
|
3443
|
+
return () => void 0;
|
|
3444
|
+
}
|
|
3445
|
+
promise.then((value) => {
|
|
3446
|
+
if (done) {
|
|
3447
|
+
recordAbortablePromiseLateSettlement(label);
|
|
3448
|
+
return;
|
|
3449
|
+
}
|
|
3450
|
+
finish("success", _chunkMVGUEJ5Zcjs.Exit.succeed(value));
|
|
3451
|
+
}).catch((err) => {
|
|
3452
|
+
if (done) {
|
|
3453
|
+
recordAbortablePromiseLateSettlement(label);
|
|
3454
|
+
return;
|
|
3455
|
+
}
|
|
3456
|
+
finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
|
|
3457
|
+
});
|
|
3458
|
+
return () => {
|
|
3459
|
+
if (done) return;
|
|
3460
|
+
try {
|
|
3461
|
+
controller.abort();
|
|
3462
|
+
} catch (e11) {
|
|
3463
|
+
}
|
|
3464
|
+
finish("interrupt", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt()));
|
|
3465
|
+
};
|
|
3466
|
+
}
|
|
3467
|
+
function registerWithoutTimeout(make, onReject, options, env, cb) {
|
|
3468
|
+
const controller = new AbortController();
|
|
3469
|
+
const label = normalizeAbortablePromiseLabel(options.label);
|
|
3470
|
+
const startedAt = performance.now();
|
|
3471
|
+
let done = false;
|
|
3472
|
+
const hasHooks = options.onStart !== void 0 || options.onFinish !== void 0;
|
|
3473
|
+
const finish = hasHooks ? (outcome, exit, error) => {
|
|
3474
|
+
if (done) return;
|
|
3475
|
+
done = true;
|
|
3476
|
+
recordAbortablePromiseFinish(label, outcome);
|
|
3477
|
+
_optionalChain([options, 'access', _195 => _195.onFinish, 'optionalCall', _196 => _196({
|
|
3478
|
+
label,
|
|
3479
|
+
outcome,
|
|
3480
|
+
durationMs: Math.round(performance.now() - startedAt),
|
|
3481
|
+
error
|
|
3482
|
+
})]);
|
|
3483
|
+
cb(exit);
|
|
3484
|
+
} : (outcome, exit, _error) => {
|
|
3485
|
+
if (done) return;
|
|
3486
|
+
done = true;
|
|
3487
|
+
recordAbortablePromiseFinish(label, outcome);
|
|
3488
|
+
cb(exit);
|
|
3489
|
+
};
|
|
3490
|
+
recordAbortablePromiseStart(label);
|
|
3491
|
+
if (hasHooks) _optionalChain([options, 'access', _197 => _197.onStart, 'optionalCall', _198 => _198(label)]);
|
|
3492
|
+
let promise;
|
|
3493
|
+
try {
|
|
3494
|
+
promise = make(controller.signal, env);
|
|
3495
|
+
} catch (err) {
|
|
3496
|
+
finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
|
|
3497
|
+
return () => void 0;
|
|
3498
|
+
}
|
|
3499
|
+
promise.then((value) => {
|
|
3500
|
+
if (done) {
|
|
3501
|
+
recordAbortablePromiseLateSettlement(label);
|
|
3502
|
+
return;
|
|
3503
|
+
}
|
|
3504
|
+
finish("success", _chunkMVGUEJ5Zcjs.Exit.succeed(value));
|
|
3505
|
+
}).catch((err) => {
|
|
3506
|
+
if (done) {
|
|
3507
|
+
recordAbortablePromiseLateSettlement(label);
|
|
3508
|
+
return;
|
|
3509
|
+
}
|
|
3510
|
+
finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
|
|
3511
|
+
});
|
|
3512
|
+
return () => {
|
|
3513
|
+
if (done) return;
|
|
3514
|
+
try {
|
|
3515
|
+
controller.abort();
|
|
3516
|
+
} catch (e12) {
|
|
3517
|
+
}
|
|
3518
|
+
finish("interrupt", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt()));
|
|
3519
|
+
};
|
|
3520
|
+
}
|
|
3350
3521
|
function fromPromiseAbortable(make, onReject, options = {}) {
|
|
3351
3522
|
return {
|
|
3352
3523
|
_tag: "Async",
|
|
3353
3524
|
register: (env, cb) => {
|
|
3354
|
-
const controller = new AbortController();
|
|
3355
|
-
const label = normalizeAbortablePromiseLabel(options.label);
|
|
3356
3525
|
const timeoutMs = options.timeoutMs !== void 0 && Number.isFinite(options.timeoutMs) ? Math.max(0, Math.floor(options.timeoutMs)) : void 0;
|
|
3357
|
-
const startedAt = performance.now();
|
|
3358
|
-
let done = false;
|
|
3359
|
-
let timeoutHandle;
|
|
3360
|
-
const cleanup = () => {
|
|
3361
|
-
if (timeoutHandle !== void 0) {
|
|
3362
|
-
clearTimeout(timeoutHandle);
|
|
3363
|
-
timeoutHandle = void 0;
|
|
3364
|
-
}
|
|
3365
|
-
};
|
|
3366
|
-
const finish = (outcome, exit, error) => {
|
|
3367
|
-
if (done) return;
|
|
3368
|
-
done = true;
|
|
3369
|
-
cleanup();
|
|
3370
|
-
recordAbortablePromiseFinish(label, outcome);
|
|
3371
|
-
_optionalChain([options, 'access', _189 => _189.onFinish, 'optionalCall', _190 => _190({
|
|
3372
|
-
label,
|
|
3373
|
-
outcome,
|
|
3374
|
-
durationMs: Math.round(performance.now() - startedAt),
|
|
3375
|
-
error
|
|
3376
|
-
})]);
|
|
3377
|
-
cb(exit);
|
|
3378
|
-
};
|
|
3379
|
-
recordAbortablePromiseStart(label);
|
|
3380
|
-
_optionalChain([options, 'access', _191 => _191.onStart, 'optionalCall', _192 => _192(label)]);
|
|
3381
3526
|
if (timeoutMs !== void 0 && timeoutMs > 0) {
|
|
3382
|
-
|
|
3383
|
-
const reason = _nullishCoalesce(_optionalChain([options, 'access', _193 => _193.timeoutReason, 'optionalCall', _194 => _194()]), () => ( makeTimeoutReason(timeoutMs, label)));
|
|
3384
|
-
try {
|
|
3385
|
-
controller.abort(reason);
|
|
3386
|
-
} catch (e10) {
|
|
3387
|
-
controller.abort();
|
|
3388
|
-
}
|
|
3389
|
-
finish("timeout", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(reason))), reason);
|
|
3390
|
-
}, timeoutMs);
|
|
3527
|
+
return registerWithTimeout(make, onReject, options, env, cb, timeoutMs);
|
|
3391
3528
|
}
|
|
3392
|
-
|
|
3393
|
-
try {
|
|
3394
|
-
promise = make(controller.signal, env);
|
|
3395
|
-
} catch (err) {
|
|
3396
|
-
finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
|
|
3397
|
-
return () => void 0;
|
|
3398
|
-
}
|
|
3399
|
-
promise.then((value) => {
|
|
3400
|
-
if (done) {
|
|
3401
|
-
recordAbortablePromiseLateSettlement(label);
|
|
3402
|
-
return;
|
|
3403
|
-
}
|
|
3404
|
-
finish("success", _chunkMVGUEJ5Zcjs.Exit.succeed(value));
|
|
3405
|
-
}).catch((err) => {
|
|
3406
|
-
if (done) {
|
|
3407
|
-
recordAbortablePromiseLateSettlement(label);
|
|
3408
|
-
return;
|
|
3409
|
-
}
|
|
3410
|
-
finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
|
|
3411
|
-
});
|
|
3412
|
-
return () => {
|
|
3413
|
-
if (done) return;
|
|
3414
|
-
try {
|
|
3415
|
-
controller.abort();
|
|
3416
|
-
} catch (e11) {
|
|
3417
|
-
}
|
|
3418
|
-
finish("interrupt", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt()));
|
|
3419
|
-
};
|
|
3529
|
+
return registerWithoutTimeout(make, onReject, options, env, cb);
|
|
3420
3530
|
}
|
|
3421
3531
|
};
|
|
3422
3532
|
}
|
|
@@ -3504,7 +3614,7 @@ var RuntimeFiber = (_class17 = class {
|
|
|
3504
3614
|
return;
|
|
3505
3615
|
}
|
|
3506
3616
|
this._syncResolved = true;
|
|
3507
|
-
_optionalChain([this, 'access',
|
|
3617
|
+
_optionalChain([this, 'access', _199 => _199._asyncDetach, 'optionalCall', _200 => _200()]);
|
|
3508
3618
|
this._asyncDetach = void 0;
|
|
3509
3619
|
if (exit._tag === "Success") {
|
|
3510
3620
|
this.current = _chunkMVGUEJ5Zcjs.Async.succeed(exit.value);
|
|
@@ -3546,12 +3656,12 @@ var RuntimeFiber = (_class17 = class {
|
|
|
3546
3656
|
this.runtime.hooks.emit(ev, {
|
|
3547
3657
|
fiberId: this.id,
|
|
3548
3658
|
scopeId: this.scopeId,
|
|
3549
|
-
traceId: _optionalChain([this, 'access',
|
|
3550
|
-
spanId: _optionalChain([this, 'access',
|
|
3551
|
-
parentSpanId: _optionalChain([this, 'access',
|
|
3552
|
-
traceState: _optionalChain([this, 'access',
|
|
3553
|
-
baggage: _optionalChain([this, 'access',
|
|
3554
|
-
sampled: _optionalChain([this, 'access',
|
|
3659
|
+
traceId: _optionalChain([this, 'access', _201 => _201.fiberContext, 'optionalAccess', _202 => _202.trace, 'optionalAccess', _203 => _203.traceId]),
|
|
3660
|
+
spanId: _optionalChain([this, 'access', _204 => _204.fiberContext, 'optionalAccess', _205 => _205.trace, 'optionalAccess', _206 => _206.spanId]),
|
|
3661
|
+
parentSpanId: _optionalChain([this, 'access', _207 => _207.fiberContext, 'optionalAccess', _208 => _208.trace, 'optionalAccess', _209 => _209.parentSpanId]),
|
|
3662
|
+
traceState: _optionalChain([this, 'access', _210 => _210.fiberContext, 'optionalAccess', _211 => _211.trace, 'optionalAccess', _212 => _212.traceState]),
|
|
3663
|
+
baggage: _optionalChain([this, 'access', _213 => _213.fiberContext, 'optionalAccess', _214 => _214.trace, 'optionalAccess', _215 => _215.baggage]),
|
|
3664
|
+
sampled: _optionalChain([this, 'access', _216 => _216.fiberContext, 'optionalAccess', _217 => _217.trace, 'optionalAccess', _218 => _218.sampled])
|
|
3555
3665
|
});
|
|
3556
3666
|
}
|
|
3557
3667
|
addFinalizer(f) {
|
|
@@ -3616,7 +3726,7 @@ var RuntimeFiber = (_class17 = class {
|
|
|
3616
3726
|
unsafeRunAsync(eff, this.env, () => {
|
|
3617
3727
|
});
|
|
3618
3728
|
}
|
|
3619
|
-
} catch (
|
|
3729
|
+
} catch (e13) {
|
|
3620
3730
|
}
|
|
3621
3731
|
}
|
|
3622
3732
|
}
|
|
@@ -3805,7 +3915,7 @@ var RuntimeFiber = (_class17 = class {
|
|
|
3805
3915
|
this._asyncDetach = void 0;
|
|
3806
3916
|
try {
|
|
3807
3917
|
canceler();
|
|
3808
|
-
} catch (
|
|
3918
|
+
} catch (e14) {
|
|
3809
3919
|
}
|
|
3810
3920
|
});
|
|
3811
3921
|
}
|
|
@@ -3890,7 +4000,7 @@ var RuntimeFiber = (_class17 = class {
|
|
|
3890
4000
|
syncTrampoline() {
|
|
3891
4001
|
while (this.budget-- > 0) {
|
|
3892
4002
|
let cur = this.current;
|
|
3893
|
-
while (cur._tag === "FlatMap" && _optionalChain([cur, 'access',
|
|
4003
|
+
while (cur._tag === "FlatMap" && _optionalChain([cur, 'access', _219 => _219.first, 'optionalAccess', _220 => _220._tag]) === "FlatMap") {
|
|
3894
4004
|
this.stack.push({ _tag: "SuccessCont", k: cur.andThen });
|
|
3895
4005
|
cur = cur.first;
|
|
3896
4006
|
}
|
|
@@ -3960,7 +4070,7 @@ var RuntimeFiber = (_class17 = class {
|
|
|
3960
4070
|
this._asyncDetach = void 0;
|
|
3961
4071
|
try {
|
|
3962
4072
|
canceler();
|
|
3963
|
-
} catch (
|
|
4073
|
+
} catch (e15) {
|
|
3964
4074
|
}
|
|
3965
4075
|
});
|
|
3966
4076
|
}
|
|
@@ -3991,7 +4101,7 @@ function getCurrentFiber() {
|
|
|
3991
4101
|
}
|
|
3992
4102
|
function unsafeGetCurrentRuntime() {
|
|
3993
4103
|
const f = getCurrentFiber();
|
|
3994
|
-
if (!_optionalChain([f, 'optionalAccess',
|
|
4104
|
+
if (!_optionalChain([f, 'optionalAccess', _221 => _221.runtime])) {
|
|
3995
4105
|
throw new Error("unsafeGetCurrentRuntime: no current fiber/runtime");
|
|
3996
4106
|
}
|
|
3997
4107
|
return f.runtime;
|
|
@@ -4035,6 +4145,189 @@ var JsFiberEngine = (_class18 = class {
|
|
|
4035
4145
|
}
|
|
4036
4146
|
}, _class18);
|
|
4037
4147
|
|
|
4148
|
+
// src/core/runtime/scope.ts
|
|
4149
|
+
var nextScopeId = 1;
|
|
4150
|
+
function awaitAll(fibers) {
|
|
4151
|
+
return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (_env, cb) => {
|
|
4152
|
+
let remaining = fibers.length;
|
|
4153
|
+
if (remaining === 0) {
|
|
4154
|
+
cb({ _tag: "Success", value: void 0 });
|
|
4155
|
+
return;
|
|
4156
|
+
}
|
|
4157
|
+
for (const f of fibers) {
|
|
4158
|
+
f.join(() => {
|
|
4159
|
+
remaining -= 1;
|
|
4160
|
+
if (remaining === 0) cb({ _tag: "Success", value: void 0 });
|
|
4161
|
+
});
|
|
4162
|
+
}
|
|
4163
|
+
});
|
|
4164
|
+
}
|
|
4165
|
+
var Scope = (_class19 = class _Scope {
|
|
4166
|
+
constructor(runtime, parentScopeId) {;_class19.prototype.__init119.call(this);_class19.prototype.__init120.call(this);_class19.prototype.__init121.call(this);_class19.prototype.__init122.call(this);
|
|
4167
|
+
this.runtime = runtime;
|
|
4168
|
+
this.parentScopeId = parentScopeId;
|
|
4169
|
+
this.id = nextScopeId++;
|
|
4170
|
+
const inferredParent = _nullishCoalesce(this.parentScopeId, () => ( _optionalChain([getCurrentFiber, 'call', _222 => _222(), 'optionalAccess', _223 => _223.scopeId])));
|
|
4171
|
+
if (this.runtime.hasActiveHooks()) {
|
|
4172
|
+
this.runtime.emit({
|
|
4173
|
+
type: "scope.open",
|
|
4174
|
+
scopeId: this.id,
|
|
4175
|
+
parentScopeId: inferredParent
|
|
4176
|
+
});
|
|
4177
|
+
}
|
|
4178
|
+
}
|
|
4179
|
+
|
|
4180
|
+
|
|
4181
|
+
|
|
4182
|
+
__init119() {this.closed = false}
|
|
4183
|
+
__init120() {this.children = /* @__PURE__ */ new Set()}
|
|
4184
|
+
__init121() {this.subScopes = /* @__PURE__ */ new Set()}
|
|
4185
|
+
__init122() {this.finalizers = []}
|
|
4186
|
+
/** registra un finalizer (LIFO) */
|
|
4187
|
+
addFinalizer(f) {
|
|
4188
|
+
if (this.closed) {
|
|
4189
|
+
throw new Error("Trying to add finalizer to closed scope");
|
|
4190
|
+
}
|
|
4191
|
+
this.finalizers.push(f);
|
|
4192
|
+
}
|
|
4193
|
+
/** crea un sub scope (mismo runtime) */
|
|
4194
|
+
subScope() {
|
|
4195
|
+
if (this.closed) throw new Error("Scope closed");
|
|
4196
|
+
const s = new _Scope(this.runtime, this.id);
|
|
4197
|
+
this.subScopes.add(s);
|
|
4198
|
+
return s;
|
|
4199
|
+
}
|
|
4200
|
+
/** ✅ fork en este scope */
|
|
4201
|
+
fork(eff) {
|
|
4202
|
+
if (this.closed) throw new Error("Scope closed");
|
|
4203
|
+
const f = this.runtime.fork(eff, this.id);
|
|
4204
|
+
this.children.add(f);
|
|
4205
|
+
f.join(() => this.children.delete(f));
|
|
4206
|
+
return f;
|
|
4207
|
+
}
|
|
4208
|
+
/** close fire-and-forget (no bloquea) */
|
|
4209
|
+
close(exit = { _tag: "Success", value: void 0 }) {
|
|
4210
|
+
this.runtime.fork(this.closeAsync(exit));
|
|
4211
|
+
}
|
|
4212
|
+
/** Emit the scope.close event if hooks are active. */
|
|
4213
|
+
emitCloseEvent(exit) {
|
|
4214
|
+
if (this.runtime.hasActiveHooks()) {
|
|
4215
|
+
const status = exit._tag === "Success" ? "success" : _chunkMVGUEJ5Zcjs.Cause.isInterruptedOnly(exit.cause) ? "interrupted" : "failure";
|
|
4216
|
+
const failure = exit._tag === "Failure" ? _chunkMVGUEJ5Zcjs.Cause.firstFailure(exit.cause) : void 0;
|
|
4217
|
+
this.runtime.emit({
|
|
4218
|
+
type: "scope.close",
|
|
4219
|
+
scopeId: this.id,
|
|
4220
|
+
status,
|
|
4221
|
+
error: _optionalChain([failure, 'optionalAccess', _224 => _224._tag]) === "Some" ? failure.value : exit._tag === "Failure" ? exit.cause : void 0
|
|
4222
|
+
});
|
|
4223
|
+
}
|
|
4224
|
+
}
|
|
4225
|
+
/**
|
|
4226
|
+
* Build an effect that executes finalizers in LIFO order.
|
|
4227
|
+
*
|
|
4228
|
+
* Optimization over the original: instead of wrapping every finalizer in
|
|
4229
|
+
* `asyncFold(fin(exit), () => unit(), () => unit())` which creates 3 effect
|
|
4230
|
+
* nodes per finalizer (Fold + 2 Succeed), we use a single Sync thunk per
|
|
4231
|
+
* finalizer that catches errors inline. When the finalizer returns a
|
|
4232
|
+
* Succeed effect (like `unit()`), the Sync thunk completes without creating
|
|
4233
|
+
* additional effect nodes.
|
|
4234
|
+
*/
|
|
4235
|
+
buildFinalizerEffect(exit) {
|
|
4236
|
+
const fins = this.finalizers;
|
|
4237
|
+
if (fins.length === 0) return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
|
|
4238
|
+
let chain = _chunkMVGUEJ5Zcjs.unit.call(void 0, );
|
|
4239
|
+
for (let i = fins.length - 1; i >= 0; i--) {
|
|
4240
|
+
const fin = fins[i];
|
|
4241
|
+
chain = _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, chain, () => {
|
|
4242
|
+
let result;
|
|
4243
|
+
try {
|
|
4244
|
+
result = fin(exit);
|
|
4245
|
+
} catch (e16) {
|
|
4246
|
+
return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
|
|
4247
|
+
}
|
|
4248
|
+
if (result._tag === "Succeed") {
|
|
4249
|
+
return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
|
|
4250
|
+
}
|
|
4251
|
+
return _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
|
|
4252
|
+
result,
|
|
4253
|
+
() => _chunkMVGUEJ5Zcjs.unit.call(void 0, ),
|
|
4254
|
+
() => _chunkMVGUEJ5Zcjs.unit.call(void 0, )
|
|
4255
|
+
);
|
|
4256
|
+
});
|
|
4257
|
+
}
|
|
4258
|
+
return chain;
|
|
4259
|
+
}
|
|
4260
|
+
closeAsync(exit = { _tag: "Success", value: void 0 }, opts = { awaitChildren: true }) {
|
|
4261
|
+
return _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
|
|
4262
|
+
_chunkMVGUEJ5Zcjs.unit.call(void 0, ),
|
|
4263
|
+
() => _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env, cb) => {
|
|
4264
|
+
if (this.closed) {
|
|
4265
|
+
cb({ _tag: "Success", value: void 0 });
|
|
4266
|
+
return;
|
|
4267
|
+
}
|
|
4268
|
+
this.closed = true;
|
|
4269
|
+
const children = Array.from(this.children);
|
|
4270
|
+
const subScopes = Array.from(this.subScopes);
|
|
4271
|
+
for (const child of children) {
|
|
4272
|
+
child.interrupt();
|
|
4273
|
+
}
|
|
4274
|
+
const closeSubs = subScopes.reduceRight(
|
|
4275
|
+
(acc, s) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, acc, () => s.closeAsync(exit, opts)),
|
|
4276
|
+
_chunkMVGUEJ5Zcjs.unit.call(void 0, )
|
|
4277
|
+
);
|
|
4278
|
+
const runFinalizers = this.buildFinalizerEffect(exit);
|
|
4279
|
+
const needsAwait = opts.awaitChildren && children.length > 0;
|
|
4280
|
+
const awaitChildrenEff = needsAwait ? awaitAll(children) : _chunkMVGUEJ5Zcjs.unit.call(void 0, );
|
|
4281
|
+
const hasSubScopes = subScopes.length > 0;
|
|
4282
|
+
const hasNoFinalizers = this.finalizers.length === 0;
|
|
4283
|
+
if (!hasSubScopes && !needsAwait && hasNoFinalizers) {
|
|
4284
|
+
this.emitCloseEvent(exit);
|
|
4285
|
+
cb({ _tag: "Success", value: void 0 });
|
|
4286
|
+
return;
|
|
4287
|
+
}
|
|
4288
|
+
const all = _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, closeSubs, () => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, awaitChildrenEff, () => runFinalizers));
|
|
4289
|
+
this.runtime.fork(all).join(() => {
|
|
4290
|
+
this.emitCloseEvent(exit);
|
|
4291
|
+
cb({ _tag: "Success", value: void 0 });
|
|
4292
|
+
});
|
|
4293
|
+
})
|
|
4294
|
+
);
|
|
4295
|
+
}
|
|
4296
|
+
}, _class19);
|
|
4297
|
+
function withScopeAsync(runtime, f) {
|
|
4298
|
+
return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (_env, cb) => {
|
|
4299
|
+
const scope = new Scope(runtime);
|
|
4300
|
+
let done = false;
|
|
4301
|
+
const completeAfterClose = (exit) => {
|
|
4302
|
+
runtime.fork(scope.closeAsync(exit)).join(() => {
|
|
4303
|
+
if (done) return;
|
|
4304
|
+
done = true;
|
|
4305
|
+
cb(exit);
|
|
4306
|
+
});
|
|
4307
|
+
};
|
|
4308
|
+
const fiber = runtime.fork(f(scope));
|
|
4309
|
+
fiber.join(completeAfterClose);
|
|
4310
|
+
return () => {
|
|
4311
|
+
if (done) return;
|
|
4312
|
+
fiber.interrupt();
|
|
4313
|
+
runtime.fork(scope.closeAsync(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt())));
|
|
4314
|
+
};
|
|
4315
|
+
});
|
|
4316
|
+
}
|
|
4317
|
+
function withScope(runtime, f) {
|
|
4318
|
+
return withScopeAsync(runtime, (scope) => {
|
|
4319
|
+
const out = f(scope);
|
|
4320
|
+
if (out && typeof out === "object" && "_tag" in out) return out;
|
|
4321
|
+
return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
|
|
4322
|
+
});
|
|
4323
|
+
}
|
|
4324
|
+
|
|
4325
|
+
|
|
4326
|
+
|
|
4327
|
+
|
|
4328
|
+
|
|
4329
|
+
|
|
4330
|
+
|
|
4038
4331
|
|
|
4039
4332
|
|
|
4040
4333
|
|
|
@@ -4086,4 +4379,4 @@ var JsFiberEngine = (_class18 = class {
|
|
|
4086
4379
|
|
|
4087
4380
|
|
|
4088
4381
|
|
|
4089
|
-
exports.PushStatus = PushStatus; exports.RingBuffer = RingBuffer; exports.resolveWasmModule = resolveWasmModule; exports.makeBoundedRingBuffer = makeBoundedRingBuffer; exports.sanitizeLaneKey = sanitizeLaneKey; exports.laneTag = laneTag; exports.inferCallerLaneFromStack = inferCallerLaneFromStack; exports.Scheduler = Scheduler; exports.globalScheduler = globalScheduler; exports.emptyContext = emptyContext; exports.ctxExtend = ctxExtend; exports.ctxToObject = ctxToObject; exports.DefaultHostExecutor = DefaultHostExecutor; exports.JsFiberEngine = JsFiberEngine; exports.HostRegistry = HostRegistry; exports.ProgramBuilder = ProgramBuilder; exports.EngineFiberHandle = EngineFiberHandle; exports.ABI_VERSION = ABI_VERSION; exports.EVENT_WORDS = EVENT_WORDS; exports.NONE_U32 = NONE_U32; exports.OpcodeTagCode = OpcodeTagCode; exports.EventKindCode = EventKindCode; exports.encodeOpcodeProgram = encodeOpcodeProgram; exports.encodeOpcodeNodes = encodeOpcodeNodes; exports.decodeEvent = decodeEvent; exports.decodeEventBatch = decodeEventBatch; exports.WasmPackFiberBridge = WasmPackFiberBridge; exports.WasmFiberRegistryBridge = WasmFiberRegistryBridge; exports.makeFiberReadyQueue = makeFiberReadyQueue; exports.WasmFiberEngine = WasmFiberEngine; exports.runtimeCapabilities = runtimeCapabilities; exports.liveClock = liveClock; exports.runtimeClockFromEnv = runtimeClockFromEnv; exports.NoopHooks = NoopHooks; exports.Runtime = Runtime; exports.fork = fork; exports.runtimeForCaller = runtimeForCaller; exports.toPromiseByCaller = toPromiseByCaller; exports.unsafeRunAsync = unsafeRunAsync; exports.toPromise = toPromise; exports.abortablePromiseStats = abortablePromiseStats; exports.resetAbortablePromiseStats = resetAbortablePromiseStats; exports.fromPromiseAbortable = fromPromiseAbortable; exports.unsafeRunFoldWithEnv = unsafeRunFoldWithEnv; exports.setBenchmarkBudget = setBenchmarkBudget; exports.getBenchmarkBudget = getBenchmarkBudget; exports.RuntimeFiber = RuntimeFiber; exports.getCurrentFiber = getCurrentFiber; exports.unsafeGetCurrentRuntime = unsafeGetCurrentRuntime; exports.withCurrentFiber = withCurrentFiber;
|
|
4382
|
+
exports.PushStatus = PushStatus; exports.RingBuffer = RingBuffer; exports.resolveWasmModule = resolveWasmModule; exports.makeBoundedRingBuffer = makeBoundedRingBuffer; exports.sanitizeLaneKey = sanitizeLaneKey; exports.laneTag = laneTag; exports.inferCallerLaneFromStack = inferCallerLaneFromStack; exports.Scheduler = Scheduler; exports.globalScheduler = globalScheduler; exports.emptyContext = emptyContext; exports.ctxExtend = ctxExtend; exports.ctxToObject = ctxToObject; exports.DefaultHostExecutor = DefaultHostExecutor; exports.JsFiberEngine = JsFiberEngine; exports.HostRegistry = HostRegistry; exports.ProgramBuilder = ProgramBuilder; exports.EngineFiberHandle = EngineFiberHandle; exports.ABI_VERSION = ABI_VERSION; exports.EVENT_WORDS = EVENT_WORDS; exports.NONE_U32 = NONE_U32; exports.OpcodeTagCode = OpcodeTagCode; exports.EventKindCode = EventKindCode; exports.encodeOpcodeProgram = encodeOpcodeProgram; exports.encodeOpcodeNodes = encodeOpcodeNodes; exports.decodeEvent = decodeEvent; exports.decodeEventBatch = decodeEventBatch; exports.WasmPackFiberBridge = WasmPackFiberBridge; exports.WasmFiberRegistryBridge = WasmFiberRegistryBridge; exports.makeFiberReadyQueue = makeFiberReadyQueue; exports.WasmFiberEngine = WasmFiberEngine; exports.runtimeCapabilities = runtimeCapabilities; exports.liveClock = liveClock; exports.runtimeClockFromEnv = runtimeClockFromEnv; exports.NoopHooks = NoopHooks; exports.Runtime = Runtime; exports.fork = fork; exports.runtimeForCaller = runtimeForCaller; exports.toPromiseByCaller = toPromiseByCaller; exports.unsafeRunAsync = unsafeRunAsync; exports.toPromise = toPromise; exports.setAbortablePromisePerLabelTracking = setAbortablePromisePerLabelTracking; exports.recordAbortablePromiseStart = recordAbortablePromiseStart; exports.recordAbortablePromiseFinish = recordAbortablePromiseFinish; exports.abortablePromiseStats = abortablePromiseStats; exports.resetAbortablePromiseStats = resetAbortablePromiseStats; exports.fromPromiseAbortable = fromPromiseAbortable; exports.unsafeRunFoldWithEnv = unsafeRunFoldWithEnv; exports.setBenchmarkBudget = setBenchmarkBudget; exports.getBenchmarkBudget = getBenchmarkBudget; exports.RuntimeFiber = RuntimeFiber; exports.getCurrentFiber = getCurrentFiber; exports.unsafeGetCurrentRuntime = unsafeGetCurrentRuntime; exports.withCurrentFiber = withCurrentFiber; exports.Scope = Scope; exports.withScopeAsync = withScopeAsync; exports.withScope = withScope;
|