brass-runtime 1.15.0 → 1.16.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/CHANGELOG.md +17 -0
- package/README.md +673 -136
- package/dist/agent/cli/main.cjs +40 -35
- package/dist/agent/cli/main.js +9 -4
- package/dist/agent/cli/main.mjs +9 -4
- package/dist/agent/index.cjs +8 -4
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +7 -3
- package/dist/agent/index.mjs +7 -3
- package/dist/chunk-2HQTDLHF.mjs +683 -0
- package/dist/chunk-36I3M4UC.mjs +370 -0
- package/dist/chunk-3AYM6WPJ.js +1629 -0
- package/dist/chunk-3LOYJFRR.cjs +300 -0
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/chunk-3Y2RIUMM.js +300 -0
- package/dist/{chunk-VEZNF5GZ.cjs → chunk-4ROBZFL6.cjs} +130 -126
- package/dist/{chunk-3QMOKAS5.js → chunk-52OB2ROS.js} +9 -5
- package/dist/chunk-52PPNNI4.cjs +416 -0
- package/dist/chunk-5EC274J5.cjs +2874 -0
- package/dist/chunk-5QC7LRZ3.js +229 -0
- package/dist/chunk-5VRJNBLZ.mjs +2874 -0
- package/dist/chunk-62AZW6UT.cjs +313 -0
- package/dist/chunk-6IXXWIUM.js +683 -0
- package/dist/chunk-74ZTY6CP.js +2871 -0
- package/dist/chunk-76YMRMH2.cjs +777 -0
- package/dist/chunk-7CMJS3QE.mjs +2871 -0
- package/dist/{chunk-4NHES7VK.mjs → chunk-7JIJOVCT.js} +27 -13
- package/dist/chunk-A2OM6NEH.mjs +194 -0
- package/dist/chunk-AGR5B2BC.cjs +683 -0
- package/dist/chunk-AVNQLJ5V.js +777 -0
- package/dist/chunk-B33ICAKP.js +313 -0
- package/dist/{chunk-ELOOF35R.mjs → chunk-B5JD23U7.mjs} +1 -1
- package/dist/chunk-BABBZK4Y.js +2024 -0
- package/dist/chunk-C3MDXTRZ.js +354 -0
- package/dist/chunk-CIZFIMK5.js +2193 -0
- package/dist/chunk-CZIVE6NT.cjs +354 -0
- package/dist/chunk-DNFJLJMW.mjs +354 -0
- package/dist/chunk-DNFO2EIZ.mjs +777 -0
- package/dist/chunk-EJ6BPYVR.mjs +416 -0
- package/dist/chunk-ENKODRU3.cjs +2193 -0
- package/dist/chunk-EOC4UHBS.mjs +229 -0
- package/dist/{chunk-BMH5AV44.js → chunk-FH2X7BVP.js} +756 -440
- package/dist/{chunk-PPUXIH5R.js → chunk-FHQGHPMO.mjs} +27 -13
- package/dist/{chunk-TGIFUAK4.cjs → chunk-GLE2WY7Z.cjs} +951 -635
- package/dist/{chunk-BDF4AMWX.mjs → chunk-GYM3LLGS.mjs} +756 -440
- package/dist/chunk-HLWLMW2F.mjs +2024 -0
- package/dist/chunk-JF5WGYJJ.cjs +194 -0
- package/dist/chunk-KH4SYAOS.mjs +1629 -0
- package/dist/chunk-KN32XNTH.mjs +313 -0
- package/dist/chunk-KQLYONSE.cjs +2871 -0
- package/dist/{chunk-STVLQ3XD.cjs → chunk-KZJQ723N.cjs} +92 -78
- package/dist/chunk-L2SYFEBS.js +194 -0
- package/dist/chunk-L6VB5N7Q.cjs +104 -0
- package/dist/{chunk-K6M7MDZ4.mjs → chunk-MBEJI5HF.mjs} +9 -5
- package/dist/chunk-MIIYDLGM.js +2874 -0
- package/dist/chunk-MOO4L7F4.mjs +104 -0
- package/dist/chunk-MT3OWDPC.mjs +2193 -0
- package/dist/chunk-MVGUEJ5Z.cjs +370 -0
- package/dist/chunk-OBGZSXTJ.cjs +10 -0
- package/dist/chunk-PD4EJTQC.cjs +229 -0
- package/dist/chunk-PWC3RBQE.mjs +300 -0
- package/dist/chunk-Q2I37RP3.cjs +1629 -0
- package/dist/chunk-RKGKFN2A.js +416 -0
- package/dist/{chunk-R3R2FVLG.cjs → chunk-SA6HUJVI.cjs} +5 -5
- package/dist/chunk-TRM4JUZQ.js +104 -0
- package/dist/chunk-UB4B6OFY.js +370 -0
- package/dist/{chunk-TO7IKXYT.js → chunk-UCUBNWM2.js} +1 -1
- package/dist/chunk-VN44DYYT.cjs +2024 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/client-CZHU674n.d.ts +820 -0
- package/dist/core/index.cjs +198 -4
- package/dist/core/index.d.ts +311 -212
- package/dist/core/index.js +237 -43
- package/dist/core/index.mjs +237 -43
- package/dist/{effect-CMOQKX8y.d.ts → effect-DIUHZ9IN.d.ts} +195 -1
- package/dist/effectRunner-CFLC32IK.cjs +8 -0
- package/dist/effectRunner-L4S7IPT3.js +8 -0
- package/dist/effectRunner-NNGG75QA.mjs +8 -0
- package/dist/http/index.cjs +1227 -2971
- package/dist/http/index.d.ts +826 -280
- package/dist/http/index.js +1089 -2833
- package/dist/http/index.mjs +1089 -2833
- package/dist/http/testing.cjs +161 -0
- package/dist/http/testing.d.ts +43 -0
- package/dist/http/testing.js +161 -0
- package/dist/http/testing.mjs +161 -0
- package/dist/index.cjs +486 -250
- package/dist/index.d.ts +87 -95
- package/dist/index.js +391 -155
- package/dist/index.mjs +391 -155
- package/dist/observability/index.cjs +162 -0
- package/dist/observability/index.d.ts +152 -0
- package/dist/observability/index.js +162 -0
- package/dist/observability/index.mjs +162 -0
- package/dist/perf/cli.cjs +401 -0
- package/dist/perf/cli.d.ts +1 -0
- package/dist/perf/cli.js +401 -0
- package/dist/perf/cli.mjs +401 -0
- package/dist/perf/index.cjs +141 -0
- package/dist/perf/index.d.ts +483 -0
- package/dist/perf/index.js +141 -0
- package/dist/perf/index.mjs +141 -0
- package/dist/schedule-CK3Ml_7p.d.ts +259 -0
- package/dist/schema/index.cjs +29 -0
- package/dist/schema/index.d.ts +179 -0
- package/dist/schema/index.js +29 -0
- package/dist/schema/index.mjs +29 -0
- package/dist/server-GJPg8ZSG.d.ts +675 -0
- package/dist/{stream-FQm9h4Mg.d.ts → stream-B4oK9JFP.d.ts} +1 -1
- package/dist/tracer-Hwt1cl7h.d.ts +189 -0
- package/dist/tracing-DqbTKGcf.d.ts +148 -0
- package/docs/ARCHITECTURE.md +292 -0
- package/docs/README.md +63 -0
- package/docs/adr/0001-ai-context-pack.md +32 -0
- package/docs/agent-apply-mode.md +104 -0
- package/docs/agent-approvals.md +110 -0
- package/docs/agent-batch.md +185 -0
- package/docs/agent-boundaries.md +112 -0
- package/docs/agent-chat-sessions.md +160 -0
- package/docs/agent-ci.md +17 -0
- package/docs/agent-cli.md +405 -0
- package/docs/agent-config.md +480 -0
- package/docs/agent-context-discovery.md +159 -0
- package/docs/agent-copilot-like-dx.md +126 -0
- package/docs/agent-declarative-optimized-planning.md +138 -0
- package/docs/agent-dx.md +224 -0
- package/docs/agent-env-files.md +126 -0
- package/docs/agent-follow-up-context.md +43 -0
- package/docs/agent-global-usage.md +180 -0
- package/docs/agent-init.md +109 -0
- package/docs/agent-install-and-configure.md +516 -0
- package/docs/agent-language-workspace-ux.md +99 -0
- package/docs/agent-llm-adapters.md +123 -0
- package/docs/agent-local-install.md +190 -0
- package/docs/agent-local-tests.md +51 -0
- package/docs/agent-observability.md +155 -0
- package/docs/agent-patch-quality-loop.md +162 -0
- package/docs/agent-presets.md +22 -0
- package/docs/agent-project-commands.md +237 -0
- package/docs/agent-project-intelligence.md +156 -0
- package/docs/agent-redaction.md +18 -0
- package/docs/agent-release-readiness.md +76 -0
- package/docs/agent-rollback-safety.md +162 -0
- package/docs/agent-rollback.md +23 -0
- package/docs/agent-run-artifacts.md +16 -0
- package/docs/agent-vscode-auto-discovery.md +137 -0
- package/docs/agent-vscode-batch-runner.md +100 -0
- package/docs/agent-vscode-chat-layout.md +90 -0
- package/docs/agent-vscode-clean-install.md +147 -0
- package/docs/agent-vscode-code-actions.md +70 -0
- package/docs/agent-vscode-diff-preview.md +45 -0
- package/docs/agent-vscode-inline-assist.md +56 -0
- package/docs/agent-vscode-install.md +186 -0
- package/docs/agent-vscode-model-setup.md +97 -0
- package/docs/agent-vscode-patch-preview.md +92 -0
- package/docs/agent-vscode-problems.md +79 -0
- package/docs/agent-vscode-project-dashboard.md +106 -0
- package/docs/agent-vscode-run-history.md +92 -0
- package/docs/agent-vscode-ux.md +73 -0
- package/docs/ai/INVARIANTS.md +84 -0
- package/docs/ai/PROJECT_MAP.md +338 -0
- package/docs/ai/PUBLIC_API.md +336 -0
- package/docs/ai/VALIDATION_MATRIX.md +67 -0
- package/docs/api-polish.md +37 -0
- package/docs/cancellation.md +162 -0
- package/docs/coverage.md +46 -0
- package/docs/getting-started.md +159 -0
- package/docs/guides/README.md +40 -0
- package/docs/guides/circuit-breaker.md +89 -0
- package/docs/guides/error-handling.md +91 -0
- package/docs/guides/getting-started.md +107 -0
- package/docs/guides/layers.md +189 -0
- package/docs/guides/metrics.md +101 -0
- package/docs/guides/resource-management.md +141 -0
- package/docs/guides/retry.md +215 -0
- package/docs/guides/semaphore.md +66 -0
- package/docs/guides/streams.md +117 -0
- package/docs/guides/supervisors.md +98 -0
- package/docs/guides/testing.md +162 -0
- package/docs/guides/tracing.md +71 -0
- package/docs/http-recipes.md +399 -0
- package/docs/http.md +749 -0
- package/docs/modules.md +285 -0
- package/docs/observability-collector-smoke.md +31 -0
- package/docs/observability-framework-examples.md +98 -0
- package/docs/observability.md +542 -0
- package/docs/otel-collector-smoke.yaml +27 -0
- package/docs/performance-profiler.md +199 -0
- package/docs/production-readiness.md +73 -0
- package/docs/recipes/README.md +12 -0
- package/docs/recipes/http-server.md +45 -0
- package/docs/recipes/layers.md +44 -0
- package/docs/recipes/performance.md +47 -0
- package/docs/recipes/runtime.md +41 -0
- package/docs/recipes/testing.md +41 -0
- package/docs/release.md +53 -0
- package/docs/wasm-bounded-queues.md +44 -0
- package/docs/wasm-engine-observability-benchmarks.md +85 -0
- package/docs/wasm-fiber-engine.md +117 -0
- package/docs/wasm-scheduler-state-machine.md +122 -0
- package/docs/wasm-stream-chunks.md +54 -0
- package/package.json +48 -2
- package/dist/chunk-AR22SXML.js +0 -1043
- package/dist/chunk-BDYEENHT.js +0 -224
- package/dist/chunk-JFPU5GQI.mjs +0 -1043
- package/dist/chunk-MS34J5LY.cjs +0 -224
- package/dist/chunk-UMAZLXAB.mjs +0 -224
- package/dist/chunk-XPZNXSVN.cjs +0 -1043
- package/dist/tracing-DNT9jEbr.d.ts +0 -106
|
@@ -1,121 +1,13 @@
|
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkMVGUEJ5Zcjs = require('./chunk-MVGUEJ5Z.cjs');
|
|
7
|
+
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
succeed: (value) => ({ _tag: "Succeed", value }),
|
|
11
|
-
fail: (error) => ({ _tag: "Fail", error }),
|
|
12
|
-
sync: (thunk) => ({ _tag: "Sync", thunk }),
|
|
13
|
-
async: (register) => ({ _tag: "Async", register })
|
|
14
|
-
};
|
|
15
|
-
function asyncFold(fa, onFailure, onSuccess) {
|
|
16
|
-
return {
|
|
17
|
-
_tag: "Fold",
|
|
18
|
-
first: fa,
|
|
19
|
-
onFailure,
|
|
20
|
-
onSuccess
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function asyncCatchAll(fa, handler) {
|
|
24
|
-
return asyncFold(fa, handler, asyncSucceed);
|
|
25
|
-
}
|
|
26
|
-
function asyncMapError(fa, f) {
|
|
27
|
-
return asyncFold(fa, (e) => asyncFail(f(e)), asyncSucceed);
|
|
28
|
-
}
|
|
29
|
-
var SUCCEED_UNDEFINED = { _tag: "Succeed", value: void 0 };
|
|
30
|
-
var SUCCEED_TRUE = { _tag: "Succeed", value: true };
|
|
31
|
-
var SUCCEED_FALSE = { _tag: "Succeed", value: false };
|
|
32
|
-
var SUCCEED_NULL = { _tag: "Succeed", value: null };
|
|
33
|
-
var unit = () => SUCCEED_UNDEFINED;
|
|
34
|
-
var asyncSucceed = (value) => {
|
|
35
|
-
if (value === void 0) return SUCCEED_UNDEFINED;
|
|
36
|
-
if (value === true) return SUCCEED_TRUE;
|
|
37
|
-
if (value === false) return SUCCEED_FALSE;
|
|
38
|
-
if (value === null) return SUCCEED_NULL;
|
|
39
|
-
return { _tag: "Succeed", value };
|
|
40
|
-
};
|
|
41
|
-
var asyncFail = (error) => ({
|
|
42
|
-
_tag: "Fail",
|
|
43
|
-
error
|
|
44
|
-
});
|
|
45
|
-
var asyncSync = (thunk) => ({
|
|
46
|
-
_tag: "Sync",
|
|
47
|
-
thunk
|
|
48
|
-
});
|
|
49
|
-
var asyncTotal = (thunk) => asyncSync(() => thunk());
|
|
50
|
-
var asyncEffect = (register) => ({
|
|
51
|
-
_tag: "Async",
|
|
52
|
-
register
|
|
53
|
-
});
|
|
54
|
-
function asyncMap(fa, f) {
|
|
55
|
-
return asyncFlatMap(fa, (a) => asyncSucceed(f(a)));
|
|
56
|
-
}
|
|
57
|
-
function asyncFlatMap(fa, f) {
|
|
58
|
-
return {
|
|
59
|
-
_tag: "FlatMap",
|
|
60
|
-
first: fa,
|
|
61
|
-
andThen: f
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function acquireRelease(acquire, release, scope) {
|
|
65
|
-
return asyncFlatMap(acquire, (resource) => {
|
|
66
|
-
scope.addFinalizer((exit) => release(resource, exit));
|
|
67
|
-
return asyncSucceed(resource);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function asyncInterruptible(register) {
|
|
71
|
-
return asyncEffect(register);
|
|
72
|
-
}
|
|
73
|
-
var withAsyncPromise = (run) => (eff) => {
|
|
74
|
-
const anyEff = eff;
|
|
75
|
-
if (!anyEff.toPromise) {
|
|
76
|
-
anyEff.toPromise = (env) => run(eff, env);
|
|
77
|
-
anyEff.unsafeRunPromise = () => run(eff, {});
|
|
78
|
-
}
|
|
79
|
-
return anyEff;
|
|
80
|
-
};
|
|
81
|
-
var mapAsync = (fa, f) => asyncFlatMap(fa, (a) => asyncSucceed(f(a)));
|
|
82
|
-
var mapTryAsync = (fa, f) => asyncFlatMap(fa, (a) => asyncSync(() => f(a)));
|
|
83
|
-
|
|
84
|
-
// src/core/types/option.ts
|
|
85
|
-
var none = { _tag: "None" };
|
|
86
|
-
var some = (value) => ({ _tag: "Some", value });
|
|
87
|
-
|
|
88
|
-
// src/core/types/effect.ts
|
|
89
|
-
var Cause = {
|
|
90
|
-
fail: (error) => ({ _tag: "Fail", error }),
|
|
91
|
-
interrupt: () => ({ _tag: "Interrupt" }),
|
|
92
|
-
die: (defect) => ({ _tag: "Die", defect })
|
|
93
|
-
};
|
|
94
|
-
var Exit = {
|
|
95
|
-
succeed: (value) => ({
|
|
96
|
-
_tag: "Success",
|
|
97
|
-
value
|
|
98
|
-
}),
|
|
99
|
-
failCause: (cause) => ({
|
|
100
|
-
_tag: "Failure",
|
|
101
|
-
cause
|
|
102
|
-
})
|
|
103
|
-
};
|
|
104
|
-
var succeed = (value) => asyncSucceed(value);
|
|
105
|
-
var fail = (error) => asyncFail(error);
|
|
106
|
-
var sync = (thunk) => asyncSync((env) => thunk(env));
|
|
107
|
-
var map = (fa, f) => asyncMap(fa, f);
|
|
108
|
-
var flatMap = (fa, f) => asyncFlatMap(fa, f);
|
|
109
|
-
var mapError = (fa, f) => asyncMapError(fa, f);
|
|
110
|
-
var catchAll = (fa, handler) => asyncFold(fa, handler, asyncSucceed);
|
|
111
|
-
function orElseOptional(fa, that) {
|
|
112
|
-
return asyncFold(
|
|
113
|
-
fa,
|
|
114
|
-
(opt) => opt._tag === "Some" ? asyncFail(opt) : that(),
|
|
115
|
-
asyncSucceed
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
var end = () => fail(none);
|
|
9
|
+
|
|
10
|
+
var _chunkCZIVE6NTcjs = require('./chunk-CZIVE6NT.cjs');
|
|
119
11
|
|
|
120
12
|
// src/core/runtime/ringBuffer.ts
|
|
121
13
|
var PushStatus = /* @__PURE__ */ ((PushStatus3) => {
|
|
@@ -441,13 +333,47 @@ function resolveWasmScheduler() {
|
|
|
441
333
|
var LaneState = (_class4 = class {
|
|
442
334
|
constructor(key, initial, max) {;_class4.prototype.__init16.call(this);_class4.prototype.__init17.call(this);_class4.prototype.__init18.call(this);
|
|
443
335
|
this.key = key;
|
|
336
|
+
this.initial = initial;
|
|
337
|
+
this.max = max;
|
|
444
338
|
this.queue = makeBoundedRingBuffer(initial, max, { engine: "ts" });
|
|
445
339
|
}
|
|
446
340
|
|
|
447
341
|
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
448
346
|
__init16() {this.enqueuedTasks = 0}
|
|
449
347
|
__init17() {this.executedTasks = 0}
|
|
450
348
|
__init18() {this.droppedTasks = 0}
|
|
349
|
+
recordTag(tag, queuedBefore) {
|
|
350
|
+
if (this.tagQueue) {
|
|
351
|
+
this.tagQueue.push(tag);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (queuedBefore === 0 || this.sharedTag === void 0) {
|
|
355
|
+
this.sharedTag = tag;
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (this.sharedTag === tag) return;
|
|
359
|
+
const tags = makeBoundedRingBuffer(this.initial, this.max, { engine: "ts" });
|
|
360
|
+
for (let i = 0; i < queuedBefore; i++) tags.push(this.sharedTag);
|
|
361
|
+
tags.push(tag);
|
|
362
|
+
this.tagQueue = tags;
|
|
363
|
+
}
|
|
364
|
+
shiftTag() {
|
|
365
|
+
if (this.tagQueue) {
|
|
366
|
+
const tag2 = _nullishCoalesce(_nullishCoalesce(this.tagQueue.shift(), () => ( this.sharedTag)), () => ( this.key));
|
|
367
|
+
if (this.queue.length === 0) {
|
|
368
|
+
this.tagQueue = void 0;
|
|
369
|
+
this.sharedTag = void 0;
|
|
370
|
+
}
|
|
371
|
+
return tag2;
|
|
372
|
+
}
|
|
373
|
+
const tag = _nullishCoalesce(this.sharedTag, () => ( this.key));
|
|
374
|
+
if (this.queue.length === 0) this.sharedTag = void 0;
|
|
375
|
+
return tag;
|
|
376
|
+
}
|
|
451
377
|
}, _class4);
|
|
452
378
|
var JsSchedulerState = (_class5 = class {
|
|
453
379
|
constructor(options) {;_class5.prototype.__init19.call(this);_class5.prototype.__init20.call(this);_class5.prototype.__init21.call(this);_class5.prototype.__init22.call(this);_class5.prototype.__init23.call(this);_class5.prototype.__init24.call(this);_class5.prototype.__init25.call(this);_class5.prototype.__init26.call(this);_class5.prototype.__init27.call(this);_class5.prototype.__init28.call(this);_class5.prototype.__init29.call(this);_class5.prototype.__init30.call(this);_class5.prototype.__init31.call(this);
|
|
@@ -473,12 +399,33 @@ var JsSchedulerState = (_class5 = class {
|
|
|
473
399
|
return n;
|
|
474
400
|
}
|
|
475
401
|
}, _class5);
|
|
476
|
-
var
|
|
402
|
+
var JsSingleSchedulerState = (_class6 = class {
|
|
403
|
+
constructor(options) {;_class6.prototype.__init32.call(this);_class6.prototype.__init33.call(this);_class6.prototype.__init34.call(this);_class6.prototype.__init35.call(this);_class6.prototype.__init36.call(this);_class6.prototype.__init37.call(this);_class6.prototype.__init38.call(this);_class6.prototype.__init39.call(this);_class6.prototype.__init40.call(this);
|
|
404
|
+
this.options = options;
|
|
405
|
+
this.queue = makeBoundedRingBuffer(
|
|
406
|
+
_nullishCoalesce(options.initialCapacity, () => ( 1024)),
|
|
407
|
+
_nullishCoalesce(options.maxCapacity, () => ( SCHEDULER_QUEUE_CAPACITY)),
|
|
408
|
+
{ engine: "ts" }
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
__init32() {this.flushing = false}
|
|
414
|
+
__init33() {this.scheduled = false}
|
|
415
|
+
__init34() {this.scheduledFlushes = 0}
|
|
416
|
+
__init35() {this.completedFlushes = 0}
|
|
417
|
+
__init36() {this.enqueuedTasks = 0}
|
|
418
|
+
__init37() {this.executedTasks = 0}
|
|
419
|
+
__init38() {this.droppedTasks = 0}
|
|
420
|
+
__init39() {this.yieldedByBudget = 0}
|
|
421
|
+
__init40() {this.totalLength = 0}
|
|
422
|
+
}, _class6);
|
|
423
|
+
var WasmSchedulerState = (_class7 = class {
|
|
477
424
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
constructor(options) {;
|
|
425
|
+
__init41() {this.nextRef = 1}
|
|
426
|
+
__init42() {this.tasks = /* @__PURE__ */ new Map()}
|
|
427
|
+
__init43() {this.tags = /* @__PURE__ */ new Map()}
|
|
428
|
+
constructor(options) {;_class7.prototype.__init41.call(this);_class7.prototype.__init42.call(this);_class7.prototype.__init43.call(this);
|
|
482
429
|
const Ctor = resolveWasmScheduler();
|
|
483
430
|
if (!Ctor) throw new Error("brass-runtime wasm scheduler is not available. Run npm run build:wasm first.");
|
|
484
431
|
this.machine = new Ctor(
|
|
@@ -539,7 +486,7 @@ var WasmSchedulerState = (_class6 = class {
|
|
|
539
486
|
stats() {
|
|
540
487
|
return { engine: "wasm", fallbackUsed: false, data: JSON.parse(this.machine.stats_json()) };
|
|
541
488
|
}
|
|
542
|
-
},
|
|
489
|
+
}, _class7);
|
|
543
490
|
function sanitizeLaneKey(value) {
|
|
544
491
|
let key = "";
|
|
545
492
|
let previousWasColon = false;
|
|
@@ -710,9 +657,9 @@ function inferLane(tag) {
|
|
|
710
657
|
}
|
|
711
658
|
function extractTaggedLane(tag, prefix) {
|
|
712
659
|
if (!tag.startsWith(prefix)) return void 0;
|
|
713
|
-
const
|
|
714
|
-
if (
|
|
715
|
-
const value = tag.slice(prefix.length,
|
|
660
|
+
const end = tag.indexOf("|", prefix.length);
|
|
661
|
+
if (end < 0) return void 0;
|
|
662
|
+
const value = tag.slice(prefix.length, end);
|
|
716
663
|
return value.length > 0 ? value : void 0;
|
|
717
664
|
}
|
|
718
665
|
function firstSeparatorIndex(value) {
|
|
@@ -723,7 +670,7 @@ function firstSeparatorIndex(value) {
|
|
|
723
670
|
}
|
|
724
671
|
return best;
|
|
725
672
|
}
|
|
726
|
-
var Scheduler = (
|
|
673
|
+
var Scheduler = (_class8 = class {
|
|
727
674
|
|
|
728
675
|
|
|
729
676
|
|
|
@@ -733,8 +680,10 @@ var Scheduler = (_class7 = class {
|
|
|
733
680
|
|
|
734
681
|
|
|
735
682
|
|
|
736
|
-
|
|
737
|
-
|
|
683
|
+
|
|
684
|
+
__init44() {this.boundFlush = () => this.flush()}
|
|
685
|
+
__init45() {this.shiftedTag = "anonymous"}
|
|
686
|
+
constructor(options = {}) {;_class8.prototype.__init44.call(this);_class8.prototype.__init45.call(this);
|
|
738
687
|
this.flushBudget = _nullishCoalesce(options.flushBudget, () => ( FLUSH_BUDGET));
|
|
739
688
|
this.microThreshold = _nullishCoalesce(options.microThreshold, () => ( MICRO_THRESHOLD));
|
|
740
689
|
this.laneCapacity = _nullishCoalesce(options.laneCapacity, () => ( DEFAULT_LANE_CAPACITY));
|
|
@@ -748,7 +697,11 @@ var Scheduler = (_class7 = class {
|
|
|
748
697
|
return;
|
|
749
698
|
}
|
|
750
699
|
if (requested === "ts") {
|
|
751
|
-
|
|
700
|
+
if (options.laneMode === "single") {
|
|
701
|
+
this.jsSingle = new JsSingleSchedulerState({ ...options, engine: "ts" });
|
|
702
|
+
} else {
|
|
703
|
+
this.js = new JsSchedulerState({ ...options, engine: "ts" });
|
|
704
|
+
}
|
|
752
705
|
this.engine = "ts";
|
|
753
706
|
this.fallbackUsed = false;
|
|
754
707
|
return;
|
|
@@ -758,14 +711,42 @@ var Scheduler = (_class7 = class {
|
|
|
758
711
|
schedule(task, tag = "anonymous") {
|
|
759
712
|
if (typeof task !== "function") return "dropped";
|
|
760
713
|
if (this.wasm) return this.scheduleWasm(task, tag);
|
|
714
|
+
if (this.jsSingle) return this.scheduleJsSingle(task);
|
|
761
715
|
return this.scheduleJs(task, tag);
|
|
762
716
|
}
|
|
763
717
|
scheduleBatch(tasks) {
|
|
764
718
|
if (this.wasm) return this.scheduleBatchWasm(tasks);
|
|
719
|
+
if (this.jsSingle) return this.scheduleBatchJsSingle(tasks);
|
|
765
720
|
return tasks.map(({ fn, tag }) => this.schedule(fn, tag));
|
|
766
721
|
}
|
|
767
722
|
stats() {
|
|
768
723
|
if (this.wasm) return this.wasm.stats();
|
|
724
|
+
if (this.jsSingle) {
|
|
725
|
+
const js2 = this.jsSingle;
|
|
726
|
+
return {
|
|
727
|
+
engine: "ts",
|
|
728
|
+
fallbackUsed: false,
|
|
729
|
+
data: {
|
|
730
|
+
len: js2.totalLength,
|
|
731
|
+
capacity: js2.queue.capacity,
|
|
732
|
+
phase: js2.flushing ? "flushing" : js2.scheduled ? "scheduled" : "idle",
|
|
733
|
+
scheduledFlushes: js2.scheduledFlushes,
|
|
734
|
+
completedFlushes: js2.completedFlushes,
|
|
735
|
+
enqueuedTasks: js2.enqueuedTasks,
|
|
736
|
+
executedTasks: js2.executedTasks,
|
|
737
|
+
droppedTasks: js2.droppedTasks,
|
|
738
|
+
yieldedByBudget: js2.yieldedByBudget,
|
|
739
|
+
lanes: [{
|
|
740
|
+
key: "single",
|
|
741
|
+
len: js2.queue.length,
|
|
742
|
+
capacity: js2.queue.capacity,
|
|
743
|
+
enqueuedTasks: js2.enqueuedTasks,
|
|
744
|
+
executedTasks: js2.executedTasks,
|
|
745
|
+
droppedTasks: js2.droppedTasks
|
|
746
|
+
}]
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
}
|
|
769
750
|
const js = this.js;
|
|
770
751
|
const lanes = Array.from(js.lanes.values()).map((lane) => ({ key: lane.key, len: lane.queue.length, capacity: lane.queue.capacity, enqueuedTasks: lane.enqueuedTasks, executedTasks: lane.executedTasks, droppedTasks: lane.droppedTasks }));
|
|
771
752
|
return { engine: "ts", fallbackUsed: false, data: { len: js.totalLength, capacity: js.totalCapacity, phase: js.flushing ? "flushing" : js.scheduled ? "scheduled" : "idle", scheduledFlushes: js.scheduledFlushes, completedFlushes: js.completedFlushes, enqueuedTasks: js.enqueuedTasks, executedTasks: js.executedTasks, droppedTasks: js.droppedTasks, yieldedByBudget: js.yieldedByBudget, lanes } };
|
|
@@ -821,13 +802,44 @@ var Scheduler = (_class7 = class {
|
|
|
821
802
|
const js = this.js;
|
|
822
803
|
const lane = new LaneState(key, this.laneCapacity, this.laneCapacity);
|
|
823
804
|
js.lanes.set(key, lane);
|
|
824
|
-
js.laneOrder.push(
|
|
805
|
+
js.laneOrder.push(lane);
|
|
825
806
|
return lane;
|
|
826
807
|
}
|
|
808
|
+
scheduleJsSingle(task) {
|
|
809
|
+
const js = this.jsSingle;
|
|
810
|
+
const status = js.queue.push(task);
|
|
811
|
+
js.enqueuedTasks++;
|
|
812
|
+
if ((status & 2) !== 0) {
|
|
813
|
+
js.droppedTasks++;
|
|
814
|
+
if (!js.flushing && !js.scheduled && js.totalLength > 0) {
|
|
815
|
+
js.scheduled = true;
|
|
816
|
+
js.scheduledFlushes++;
|
|
817
|
+
this.requestFlush(js.totalLength > this.microThreshold ? "macro" : "micro");
|
|
818
|
+
}
|
|
819
|
+
return "dropped";
|
|
820
|
+
}
|
|
821
|
+
js.totalLength++;
|
|
822
|
+
if (js.flushing) return "accepted";
|
|
823
|
+
if (!js.scheduled) {
|
|
824
|
+
js.scheduled = true;
|
|
825
|
+
js.scheduledFlushes++;
|
|
826
|
+
this.requestFlush(js.totalLength > this.microThreshold ? "macro" : "micro");
|
|
827
|
+
}
|
|
828
|
+
return "accepted";
|
|
829
|
+
}
|
|
830
|
+
scheduleBatchJsSingle(tasks) {
|
|
831
|
+
const results = new Array(tasks.length);
|
|
832
|
+
for (let i = 0; i < tasks.length; i++) {
|
|
833
|
+
const task = tasks[i].fn;
|
|
834
|
+
results[i] = typeof task === "function" ? this.scheduleJsSingle(task) : "dropped";
|
|
835
|
+
}
|
|
836
|
+
return results;
|
|
837
|
+
}
|
|
827
838
|
scheduleJs(task, tag) {
|
|
828
839
|
const js = this.js;
|
|
829
840
|
const lane = this.getOrCreateLane(inferLane(tag));
|
|
830
|
-
const
|
|
841
|
+
const queuedBefore = lane.queue.length;
|
|
842
|
+
const status = lane.queue.push(task);
|
|
831
843
|
lane.enqueuedTasks++;
|
|
832
844
|
js.enqueuedTasks++;
|
|
833
845
|
if ((status & 2) !== 0) {
|
|
@@ -840,6 +852,7 @@ var Scheduler = (_class7 = class {
|
|
|
840
852
|
}
|
|
841
853
|
return "dropped";
|
|
842
854
|
}
|
|
855
|
+
lane.recordTag(tag, queuedBefore);
|
|
843
856
|
js.totalLength++;
|
|
844
857
|
if (js.flushing) return "accepted";
|
|
845
858
|
if (!js.scheduled) {
|
|
@@ -855,6 +868,7 @@ var Scheduler = (_class7 = class {
|
|
|
855
868
|
}
|
|
856
869
|
flush() {
|
|
857
870
|
if (this.wasm) return this.flushWasm();
|
|
871
|
+
if (this.jsSingle) return this.flushJsSingle();
|
|
858
872
|
this.flushJs();
|
|
859
873
|
}
|
|
860
874
|
flushWasm() {
|
|
@@ -879,15 +893,47 @@ var Scheduler = (_class7 = class {
|
|
|
879
893
|
else if (policy === 1) this.requestFlush("macro");
|
|
880
894
|
}
|
|
881
895
|
}
|
|
896
|
+
flushJsSingle() {
|
|
897
|
+
const js = this.jsSingle;
|
|
898
|
+
if (js.flushing) return;
|
|
899
|
+
js.flushing = true;
|
|
900
|
+
js.scheduled = false;
|
|
901
|
+
let ran = 0;
|
|
902
|
+
try {
|
|
903
|
+
while (ran < this.flushBudget) {
|
|
904
|
+
const task = js.queue.shift();
|
|
905
|
+
if (!task) break;
|
|
906
|
+
js.totalLength--;
|
|
907
|
+
ran++;
|
|
908
|
+
js.executedTasks++;
|
|
909
|
+
try {
|
|
910
|
+
task();
|
|
911
|
+
} catch (e) {
|
|
912
|
+
console.error("[Scheduler] task threw (laneMode=single)", e);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
} finally {
|
|
916
|
+
js.flushing = false;
|
|
917
|
+
js.completedFlushes++;
|
|
918
|
+
if (js.totalLength > 0 && !js.scheduled) {
|
|
919
|
+
js.scheduled = true;
|
|
920
|
+
js.scheduledFlushes++;
|
|
921
|
+
const kind = ran >= this.flushBudget || js.totalLength > this.microThreshold ? "macro" : "micro";
|
|
922
|
+
if (ran >= this.flushBudget) js.yieldedByBudget++;
|
|
923
|
+
this.requestFlush(kind);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
882
927
|
shiftFromNextLane() {
|
|
883
928
|
const js = this.js;
|
|
884
929
|
const n = js.laneOrder.length;
|
|
885
930
|
if (n === 0) return void 0;
|
|
886
931
|
if (js.rrRemaining > 0) {
|
|
887
932
|
const currentIdx = (js.rrIndex + n - 1) % n;
|
|
888
|
-
const currentLane = js.
|
|
889
|
-
const next =
|
|
933
|
+
const currentLane = js.laneOrder[currentIdx];
|
|
934
|
+
const next = currentLane.queue.shift();
|
|
890
935
|
if (next) {
|
|
936
|
+
this.shiftedTag = currentLane.shiftTag();
|
|
891
937
|
js.rrRemaining--;
|
|
892
938
|
currentLane.executedTasks++;
|
|
893
939
|
js.totalLength--;
|
|
@@ -897,14 +943,15 @@ var Scheduler = (_class7 = class {
|
|
|
897
943
|
}
|
|
898
944
|
for (let scanned = 0; scanned < n; scanned++) {
|
|
899
945
|
const idx = js.rrIndex % n;
|
|
900
|
-
const
|
|
946
|
+
const lane = js.laneOrder[idx];
|
|
901
947
|
js.rrIndex = (idx + 1) % n;
|
|
902
|
-
|
|
903
|
-
if (!lane || lane.queue.length === 0) continue;
|
|
948
|
+
if (lane.queue.length === 0) continue;
|
|
904
949
|
js.rrRemaining = Math.max(0, this.laneBudget - 1);
|
|
905
950
|
lane.executedTasks++;
|
|
906
951
|
js.totalLength--;
|
|
907
|
-
|
|
952
|
+
const next = lane.queue.shift();
|
|
953
|
+
if (next) this.shiftedTag = lane.shiftTag();
|
|
954
|
+
return next;
|
|
908
955
|
}
|
|
909
956
|
return void 0;
|
|
910
957
|
}
|
|
@@ -921,9 +968,9 @@ var Scheduler = (_class7 = class {
|
|
|
921
968
|
ran++;
|
|
922
969
|
js.executedTasks++;
|
|
923
970
|
try {
|
|
924
|
-
next
|
|
971
|
+
next();
|
|
925
972
|
} catch (e) {
|
|
926
|
-
console.error(`[Scheduler] task threw (tag=${
|
|
973
|
+
console.error(`[Scheduler] task threw (tag=${this.shiftedTag})`, e);
|
|
927
974
|
}
|
|
928
975
|
}
|
|
929
976
|
} finally {
|
|
@@ -938,9 +985,30 @@ var Scheduler = (_class7 = class {
|
|
|
938
985
|
}
|
|
939
986
|
}
|
|
940
987
|
}
|
|
941
|
-
},
|
|
988
|
+
}, _class8);
|
|
942
989
|
var globalScheduler = new Scheduler();
|
|
943
990
|
|
|
991
|
+
// src/core/runtime/contex.ts
|
|
992
|
+
var emptyContext = { parent: null, patch: /* @__PURE__ */ Object.create(null) };
|
|
993
|
+
function ctxExtend(parent, patch) {
|
|
994
|
+
return { parent, patch };
|
|
995
|
+
}
|
|
996
|
+
function ctxToObject(ctx) {
|
|
997
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
998
|
+
const seen = /* @__PURE__ */ new Set();
|
|
999
|
+
let cur = ctx;
|
|
1000
|
+
while (cur) {
|
|
1001
|
+
for (const k of Object.keys(cur.patch)) {
|
|
1002
|
+
if (!seen.has(k)) {
|
|
1003
|
+
out[k] = cur.patch[k];
|
|
1004
|
+
seen.add(k);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
cur = cur.parent;
|
|
1008
|
+
}
|
|
1009
|
+
return out;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
944
1012
|
// src/core/runtime/hostAction.ts
|
|
945
1013
|
var DefaultHostExecutor = {
|
|
946
1014
|
async execute(action) {
|
|
@@ -952,33 +1020,40 @@ var DefaultHostExecutor = {
|
|
|
952
1020
|
}
|
|
953
1021
|
};
|
|
954
1022
|
|
|
955
|
-
// src/core/runtime/contex.ts
|
|
956
|
-
var emptyContext = { parent: null, patch: /* @__PURE__ */ Object.create(null) };
|
|
957
|
-
|
|
958
1023
|
// src/core/runtime/forkPolicy.ts
|
|
959
1024
|
function makeForkPolicy(env, hooks) {
|
|
960
1025
|
const svc = resolveForkServices(env);
|
|
961
1026
|
return {
|
|
962
1027
|
initChild(fiber, parent, scopeId) {
|
|
963
|
-
const parentCtx = _optionalChain([parent, 'optionalAccess',
|
|
964
|
-
const trace = forkTrace(svc, _nullishCoalesce(_optionalChain([parentCtx, 'optionalAccess',
|
|
1028
|
+
const parentCtx = _optionalChain([parent, 'optionalAccess', _4 => _4.fiberContext]);
|
|
1029
|
+
const trace = forkTrace(svc, _nullishCoalesce(_optionalChain([parentCtx, 'optionalAccess', _5 => _5.trace]), () => ( null)));
|
|
965
1030
|
fiber.fiberContext = {
|
|
966
|
-
log: _nullishCoalesce(_optionalChain([parentCtx, 'optionalAccess',
|
|
967
|
-
trace
|
|
1031
|
+
log: _nullishCoalesce(_optionalChain([parentCtx, 'optionalAccess', _6 => _6.log]), () => ( emptyContext)),
|
|
1032
|
+
trace,
|
|
1033
|
+
fiberRefs: _optionalChain([parentCtx, 'optionalAccess', _7 => _7.fiberRefs]) ? new Map(parentCtx.fiberRefs) : void 0
|
|
968
1034
|
};
|
|
969
|
-
fiber.parentFiberId = _optionalChain([parent, 'optionalAccess',
|
|
970
|
-
fiber.name = svc.childName(_optionalChain([parent, 'optionalAccess',
|
|
1035
|
+
fiber.parentFiberId = _optionalChain([parent, 'optionalAccess', _8 => _8.id]);
|
|
1036
|
+
fiber.name = svc.childName(_optionalChain([parent, 'optionalAccess', _9 => _9.name]));
|
|
971
1037
|
if (scopeId !== void 0) fiber.scopeId = scopeId;
|
|
972
1038
|
hooks.emit(
|
|
973
1039
|
{
|
|
974
1040
|
type: "fiber.start",
|
|
975
1041
|
fiberId: fiber.id,
|
|
976
|
-
parentFiberId: _optionalChain([parent, 'optionalAccess',
|
|
1042
|
+
parentFiberId: _optionalChain([parent, 'optionalAccess', _10 => _10.id]),
|
|
977
1043
|
scopeId: fiber.scopeId,
|
|
978
1044
|
// ✅ ahora viaja
|
|
979
1045
|
name: fiber.name
|
|
980
1046
|
},
|
|
981
|
-
{
|
|
1047
|
+
{
|
|
1048
|
+
fiberId: fiber.id,
|
|
1049
|
+
scopeId: fiber.scopeId,
|
|
1050
|
+
traceId: _optionalChain([trace, 'optionalAccess', _11 => _11.traceId]),
|
|
1051
|
+
spanId: _optionalChain([trace, 'optionalAccess', _12 => _12.spanId]),
|
|
1052
|
+
parentSpanId: _optionalChain([trace, 'optionalAccess', _13 => _13.parentSpanId]),
|
|
1053
|
+
traceState: _optionalChain([trace, 'optionalAccess', _14 => _14.traceState]),
|
|
1054
|
+
baggage: _optionalChain([trace, 'optionalAccess', _15 => _15.baggage]),
|
|
1055
|
+
sampled: _optionalChain([trace, 'optionalAccess', _16 => _16.sampled])
|
|
1056
|
+
}
|
|
982
1057
|
);
|
|
983
1058
|
}
|
|
984
1059
|
};
|
|
@@ -988,11 +1063,12 @@ function resolveForkServices(env) {
|
|
|
988
1063
|
newTraceId: () => randomRuntimeId("trace"),
|
|
989
1064
|
newSpanId: () => randomRuntimeId("span")
|
|
990
1065
|
};
|
|
991
|
-
const brass = _optionalChain([env, 'optionalAccess',
|
|
992
|
-
const tracer = _nullishCoalesce(_optionalChain([brass, 'optionalAccess',
|
|
993
|
-
const seed = _optionalChain([brass, 'optionalAccess',
|
|
1066
|
+
const brass = _optionalChain([env, 'optionalAccess', _17 => _17.brass]);
|
|
1067
|
+
const tracer = _nullishCoalesce(_optionalChain([brass, 'optionalAccess', _18 => _18.tracer]), () => ( defaultTracer));
|
|
1068
|
+
const seed = _optionalChain([brass, 'optionalAccess', _19 => _19.traceSeed]);
|
|
1069
|
+
const baggage = _optionalChain([brass, 'optionalAccess', _20 => _20.baggage]);
|
|
994
1070
|
const childName = _nullishCoalesce(_optionalChain([brass, 'optionalAccess', _21 => _21.childName]), () => ( ((p) => p ? `${p}/child` : void 0)));
|
|
995
|
-
return { tracer, seed, childName };
|
|
1071
|
+
return { tracer, seed, baggage, childName };
|
|
996
1072
|
}
|
|
997
1073
|
function randomRuntimeId(prefix) {
|
|
998
1074
|
const cryptoLike = globalThis.crypto;
|
|
@@ -1007,11 +1083,22 @@ function forkTrace(svc, parentTrace) {
|
|
|
1007
1083
|
traceId: parentTrace.traceId,
|
|
1008
1084
|
spanId: svc.tracer.newSpanId(),
|
|
1009
1085
|
parentSpanId: parentTrace.spanId,
|
|
1010
|
-
sampled: parentTrace.sampled
|
|
1086
|
+
sampled: parentTrace.sampled,
|
|
1087
|
+
traceState: parentTrace.traceState,
|
|
1088
|
+
baggage: parentTrace.baggage
|
|
1011
1089
|
};
|
|
1012
1090
|
}
|
|
1013
|
-
if (svc.seed)
|
|
1014
|
-
|
|
1091
|
+
if (svc.seed) {
|
|
1092
|
+
const baggage2 = _nullishCoalesce(svc.seed.baggage, () => ( svc.baggage));
|
|
1093
|
+
return baggage2 ? { ...svc.seed, baggage: baggage2 } : { ...svc.seed };
|
|
1094
|
+
}
|
|
1095
|
+
const baggage = svc.baggage;
|
|
1096
|
+
return {
|
|
1097
|
+
traceId: svc.tracer.newTraceId(),
|
|
1098
|
+
spanId: svc.tracer.newSpanId(),
|
|
1099
|
+
sampled: true,
|
|
1100
|
+
...baggage ? { baggage } : {}
|
|
1101
|
+
};
|
|
1015
1102
|
}
|
|
1016
1103
|
|
|
1017
1104
|
// src/core/runtime/engine/opcodes.ts
|
|
@@ -1028,14 +1115,14 @@ function decodeRef(ref) {
|
|
|
1028
1115
|
generation: ref >>> REF_GENERATION_SHIFT & REF_GENERATION_MASK
|
|
1029
1116
|
};
|
|
1030
1117
|
}
|
|
1031
|
-
var HostRegistry = (
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1118
|
+
var HostRegistry = (_class9 = class {constructor() { _class9.prototype.__init46.call(this);_class9.prototype.__init47.call(this);_class9.prototype.__init48.call(this);_class9.prototype.__init49.call(this);_class9.prototype.__init50.call(this);_class9.prototype.__init51.call(this);_class9.prototype.__init52.call(this); }
|
|
1119
|
+
__init46() {this.slots = [{ value: void 0, generation: 0, occupied: false }]}
|
|
1120
|
+
__init47() {this.free = []}
|
|
1121
|
+
__init48() {this.live = 0}
|
|
1122
|
+
__init49() {this.allocated = 0}
|
|
1123
|
+
__init50() {this.released = 0}
|
|
1124
|
+
__init51() {this.reused = 0}
|
|
1125
|
+
__init52() {this.staleReads = 0}
|
|
1039
1126
|
register(value) {
|
|
1040
1127
|
const index = _nullishCoalesce(this.free.pop(), () => ( this.slots.length));
|
|
1041
1128
|
let slot = this.slots[index];
|
|
@@ -1104,10 +1191,10 @@ var HostRegistry = (_class8 = class {constructor() { _class8.prototype.__init36.
|
|
|
1104
1191
|
staleReads: this.staleReads
|
|
1105
1192
|
};
|
|
1106
1193
|
}
|
|
1107
|
-
},
|
|
1108
|
-
var ProgramBuilder = (
|
|
1109
|
-
|
|
1110
|
-
|
|
1194
|
+
}, _class9);
|
|
1195
|
+
var ProgramBuilder = (_class10 = class {constructor() { _class10.prototype.__init53.call(this);_class10.prototype.__init54.call(this); }
|
|
1196
|
+
__init53() {this.nodes = []}
|
|
1197
|
+
__init54() {this.registry = new HostRegistry()}
|
|
1111
1198
|
compile(effect) {
|
|
1112
1199
|
const root = this.visit(effect);
|
|
1113
1200
|
return {
|
|
@@ -1163,6 +1250,13 @@ var ProgramBuilder = (_class9 = class {constructor() { _class9.prototype.__init4
|
|
|
1163
1250
|
};
|
|
1164
1251
|
return this.add(current.scopeId === void 0 ? base : { ...base, scopeId: current.scopeId });
|
|
1165
1252
|
}
|
|
1253
|
+
case "Interruptibility":
|
|
1254
|
+
case "InterruptibilityRestore":
|
|
1255
|
+
return this.visit(current.effect);
|
|
1256
|
+
case "FiberRefLocally":
|
|
1257
|
+
return this.visit(desugarFiberRefLocally(current.refId, current.value, current.effect));
|
|
1258
|
+
case "InterruptibilityMask":
|
|
1259
|
+
return this.visit(current.body((effect2) => effect2));
|
|
1166
1260
|
case "HostAction": {
|
|
1167
1261
|
const base = {
|
|
1168
1262
|
tag: "HostAction",
|
|
@@ -1174,11 +1268,54 @@ var ProgramBuilder = (_class9 = class {constructor() { _class9.prototype.__init4
|
|
|
1174
1268
|
return this.add({ tag: "Fail", errorRef: this.registry.register(new Error(`Unknown Async opcode: ${_optionalChain([current, 'optionalAccess', _24 => _24._tag])}`)) });
|
|
1175
1269
|
}
|
|
1176
1270
|
}
|
|
1177
|
-
},
|
|
1271
|
+
}, _class10);
|
|
1272
|
+
function desugarFiberRefLocally(refId, value, effect) {
|
|
1273
|
+
return {
|
|
1274
|
+
_tag: "FlatMap",
|
|
1275
|
+
first: {
|
|
1276
|
+
_tag: "Sync",
|
|
1277
|
+
thunk: () => enterFiberRefLocal(refId, value)
|
|
1278
|
+
},
|
|
1279
|
+
andThen: (restore) => ({
|
|
1280
|
+
_tag: "Fold",
|
|
1281
|
+
first: effect,
|
|
1282
|
+
onFailure: (error) => restoreThen(restore, { _tag: "Fail", error }),
|
|
1283
|
+
onSuccess: (result) => restoreThen(restore, { _tag: "Succeed", value: result })
|
|
1284
|
+
})
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
function restoreThen(restore, next) {
|
|
1288
|
+
return {
|
|
1289
|
+
_tag: "FlatMap",
|
|
1290
|
+
first: {
|
|
1291
|
+
_tag: "Sync",
|
|
1292
|
+
thunk: () => restore()
|
|
1293
|
+
},
|
|
1294
|
+
andThen: () => next
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
function enterFiberRefLocal(refId, value) {
|
|
1298
|
+
const fiber = getCurrentFiber();
|
|
1299
|
+
if (!fiber) return () => void 0;
|
|
1300
|
+
fiber.fiberContext ??= { log: emptyContext, trace: null };
|
|
1301
|
+
const refs = fiber.fiberContext.fiberRefs ??= /* @__PURE__ */ new Map();
|
|
1302
|
+
const hadValue = refs.has(refId);
|
|
1303
|
+
const previousValue = refs.get(refId);
|
|
1304
|
+
refs.set(refId, value);
|
|
1305
|
+
let active = true;
|
|
1306
|
+
const restore = () => {
|
|
1307
|
+
if (!active) return;
|
|
1308
|
+
active = false;
|
|
1309
|
+
if (hadValue) refs.set(refId, previousValue);
|
|
1310
|
+
else refs.delete(refId);
|
|
1311
|
+
};
|
|
1312
|
+
_optionalChain([fiber, 'access', _25 => _25.addFinalizer, 'optionalCall', _26 => _26(() => restore())]);
|
|
1313
|
+
return restore;
|
|
1314
|
+
}
|
|
1178
1315
|
|
|
1179
1316
|
// src/core/runtime/engine/FiberHandleImpl.ts
|
|
1180
|
-
var EngineFiberHandle = (
|
|
1181
|
-
constructor(id, runtime, onScheduledStep, onInterrupt, onJoiner, onQueued, onScheduleDropped, onScheduleRequest) {;
|
|
1317
|
+
var EngineFiberHandle = (_class11 = class {
|
|
1318
|
+
constructor(id, runtime, onScheduledStep, onInterrupt, onJoiner, onQueued, onScheduleDropped, onScheduleRequest) {;_class11.prototype.__init55.call(this);_class11.prototype.__init56.call(this);_class11.prototype.__init57.call(this);_class11.prototype.__init58.call(this);_class11.prototype.__init59.call(this);_class11.prototype.__init60.call(this);
|
|
1182
1319
|
this.onScheduledStep = onScheduledStep;
|
|
1183
1320
|
this.onInterrupt = onInterrupt;
|
|
1184
1321
|
this.onJoiner = onJoiner;
|
|
@@ -1201,15 +1338,15 @@ var EngineFiberHandle = (_class10 = class {
|
|
|
1201
1338
|
|
|
1202
1339
|
|
|
1203
1340
|
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1341
|
+
__init55() {this.result = null}
|
|
1342
|
+
__init56() {this.joiners = []}
|
|
1343
|
+
__init57() {this.finalizers = []}
|
|
1344
|
+
__init58() {this.finalizersDrained = false}
|
|
1345
|
+
__init59() {this.internalStatus = "running"}
|
|
1346
|
+
__init60() {this.queued = false}
|
|
1210
1347
|
status() {
|
|
1211
1348
|
if (this.result == null) return "Running";
|
|
1212
|
-
if (this.result._tag === "Failure" && this.result.cause
|
|
1349
|
+
if (this.result._tag === "Failure" && _chunkMVGUEJ5Zcjs.Cause.isInterruptedOnly(this.result.cause)) return "Interrupted";
|
|
1213
1350
|
return "Done";
|
|
1214
1351
|
}
|
|
1215
1352
|
engineStatus() {
|
|
@@ -1227,13 +1364,13 @@ var EngineFiberHandle = (_class10 = class {
|
|
|
1227
1364
|
join(cb) {
|
|
1228
1365
|
if (this.result != null) cb(this.result);
|
|
1229
1366
|
else {
|
|
1230
|
-
_optionalChain([this, 'access',
|
|
1367
|
+
_optionalChain([this, 'access', _27 => _27.onJoiner, 'optionalCall', _28 => _28(this.id)]);
|
|
1231
1368
|
this.joiners.push(cb);
|
|
1232
1369
|
}
|
|
1233
1370
|
}
|
|
1234
1371
|
interrupt() {
|
|
1235
1372
|
if (this.result != null) return;
|
|
1236
|
-
this.onInterrupt(this.id, Cause.interrupt());
|
|
1373
|
+
this.onInterrupt(this.id, _chunkMVGUEJ5Zcjs.Cause.interrupt());
|
|
1237
1374
|
}
|
|
1238
1375
|
addFinalizer(f) {
|
|
1239
1376
|
this.finalizers.push(f);
|
|
@@ -1242,12 +1379,12 @@ var EngineFiberHandle = (_class10 = class {
|
|
|
1242
1379
|
if (this.result != null || this.queued) return;
|
|
1243
1380
|
this.queued = true;
|
|
1244
1381
|
this.internalStatus = "queued";
|
|
1245
|
-
_optionalChain([this, 'access',
|
|
1382
|
+
_optionalChain([this, 'access', _29 => _29.onQueued, 'optionalCall', _30 => _30(this.id)]);
|
|
1246
1383
|
const label = `wasm-fiber#${this.id}.${tag}`;
|
|
1247
1384
|
const result = this.onScheduleRequest ? this.onScheduleRequest(this.id, label) : this.scheduleWithRuntime(label);
|
|
1248
1385
|
if (result === "dropped") {
|
|
1249
1386
|
this.queued = false;
|
|
1250
|
-
_optionalChain([this, 'access',
|
|
1387
|
+
_optionalChain([this, 'access', _31 => _31.onScheduleDropped, 'optionalCall', _32 => _32(this.id, label)]);
|
|
1251
1388
|
}
|
|
1252
1389
|
}
|
|
1253
1390
|
scheduleWithRuntime(label) {
|
|
@@ -1262,28 +1399,28 @@ var EngineFiberHandle = (_class10 = class {
|
|
|
1262
1399
|
this.runtime.hooks.emit(ev, {
|
|
1263
1400
|
fiberId: this.id,
|
|
1264
1401
|
scopeId: this.scopeId,
|
|
1265
|
-
traceId: _optionalChain([this, 'access',
|
|
1266
|
-
spanId: _optionalChain([this, 'access',
|
|
1402
|
+
traceId: _optionalChain([this, 'access', _33 => _33.fiberContext, 'optionalAccess', _34 => _34.trace, 'optionalAccess', _35 => _35.traceId]),
|
|
1403
|
+
spanId: _optionalChain([this, 'access', _36 => _36.fiberContext, 'optionalAccess', _37 => _37.trace, 'optionalAccess', _38 => _38.spanId])
|
|
1267
1404
|
});
|
|
1268
1405
|
}
|
|
1269
1406
|
succeed(value) {
|
|
1270
|
-
this.complete(Exit.succeed(value));
|
|
1407
|
+
this.complete(_chunkMVGUEJ5Zcjs.Exit.succeed(value));
|
|
1271
1408
|
}
|
|
1272
1409
|
fail(error) {
|
|
1273
|
-
this.complete(Exit.failCause(Cause.fail(error)));
|
|
1410
|
+
this.complete(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(error)));
|
|
1274
1411
|
}
|
|
1275
1412
|
die(defect) {
|
|
1276
|
-
this.complete(Exit.failCause(Cause.die(defect)));
|
|
1413
|
+
this.complete(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.die(defect)));
|
|
1277
1414
|
}
|
|
1278
1415
|
interrupted() {
|
|
1279
|
-
this.complete(Exit.failCause(Cause.interrupt()));
|
|
1416
|
+
this.complete(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt()));
|
|
1280
1417
|
}
|
|
1281
1418
|
complete(exit) {
|
|
1282
1419
|
if (this.result != null) return;
|
|
1283
1420
|
this.runFinalizersOnce(exit);
|
|
1284
1421
|
this.result = exit;
|
|
1285
|
-
this.internalStatus = exit._tag === "Success" ? "done" : exit.cause
|
|
1286
|
-
const status = exit._tag === "Success" ? "success" : exit.cause
|
|
1422
|
+
this.internalStatus = exit._tag === "Success" ? "done" : _chunkMVGUEJ5Zcjs.Cause.isInterruptedOnly(exit.cause) ? "interrupted" : "failed";
|
|
1423
|
+
const status = exit._tag === "Success" ? "success" : _chunkMVGUEJ5Zcjs.Cause.isInterruptedOnly(exit.cause) ? "interrupted" : "failure";
|
|
1287
1424
|
this.emit({
|
|
1288
1425
|
type: "fiber.end",
|
|
1289
1426
|
fiberId: this.id,
|
|
@@ -1296,18 +1433,20 @@ var EngineFiberHandle = (_class10 = class {
|
|
|
1296
1433
|
runFinalizersOnce(exit) {
|
|
1297
1434
|
if (this.finalizersDrained) return;
|
|
1298
1435
|
this.finalizersDrained = true;
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1436
|
+
withCurrentFiber(this, () => {
|
|
1437
|
+
while (this.finalizers.length > 0) {
|
|
1438
|
+
const finalizer = this.finalizers.pop();
|
|
1439
|
+
try {
|
|
1440
|
+
const eff = finalizer(exit);
|
|
1441
|
+
if (eff && typeof eff === "object" && "_tag" in eff) {
|
|
1442
|
+
this.runtime.fork(eff);
|
|
1443
|
+
}
|
|
1444
|
+
} catch (e6) {
|
|
1305
1445
|
}
|
|
1306
|
-
} catch (e6) {
|
|
1307
1446
|
}
|
|
1308
|
-
}
|
|
1447
|
+
});
|
|
1309
1448
|
}
|
|
1310
|
-
},
|
|
1449
|
+
}, _class11);
|
|
1311
1450
|
|
|
1312
1451
|
// src/core/runtime/engine/binaryAbi.ts
|
|
1313
1452
|
var ABI_VERSION = 1;
|
|
@@ -1478,24 +1617,24 @@ var VM_METRIC_NAMES = [
|
|
|
1478
1617
|
"fiberSlabReleased",
|
|
1479
1618
|
"fiberSlabStaleReads"
|
|
1480
1619
|
];
|
|
1481
|
-
var WasmPackFiberBridge = (
|
|
1482
|
-
|
|
1620
|
+
var WasmPackFiberBridge = (_class12 = class {
|
|
1621
|
+
__init61() {this.kind = "wasm"}
|
|
1483
1622
|
|
|
1484
1623
|
|
|
1485
1624
|
|
|
1486
1625
|
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
constructor(modulePath) {;
|
|
1626
|
+
__init62() {this.jsonEventCalls = 0}
|
|
1627
|
+
__init63() {this.binaryEventCalls = 0}
|
|
1628
|
+
__init64() {this.zeroCopyEventCalls = 0}
|
|
1629
|
+
__init65() {this.eventsReceived = 0}
|
|
1630
|
+
__init66() {this.maxEventsPerCall = 0}
|
|
1631
|
+
__init67() {this.jsonPrograms = 0}
|
|
1632
|
+
__init68() {this.binaryPrograms = 0}
|
|
1633
|
+
__init69() {this.zeroCopyPrograms = 0}
|
|
1634
|
+
__init70() {this.jsonPatches = 0}
|
|
1635
|
+
__init71() {this.binaryPatches = 0}
|
|
1636
|
+
__init72() {this.zeroCopyPatches = 0}
|
|
1637
|
+
constructor(modulePath) {;_class12.prototype.__init61.call(this);_class12.prototype.__init62.call(this);_class12.prototype.__init63.call(this);_class12.prototype.__init64.call(this);_class12.prototype.__init65.call(this);_class12.prototype.__init66.call(this);_class12.prototype.__init67.call(this);_class12.prototype.__init68.call(this);_class12.prototype.__init69.call(this);_class12.prototype.__init70.call(this);_class12.prototype.__init71.call(this);_class12.prototype.__init72.call(this);
|
|
1499
1638
|
const mod = loadWasmModule(modulePath);
|
|
1500
1639
|
this.vm = new mod.BrassWasmVm();
|
|
1501
1640
|
this.supportsBinary = typeof this.vm.create_fiber_bin === "function" && typeof this.vm.drive_batch_bin === "function" && typeof this.vm.provide_value_bin === "function" && typeof this.vm.provide_error_bin === "function" && typeof this.vm.provide_effect_bin === "function" && typeof this.vm.interrupt_bin === "function";
|
|
@@ -1598,29 +1737,16 @@ var WasmPackFiberBridge = (_class11 = class {
|
|
|
1598
1737
|
}
|
|
1599
1738
|
decodeZeroCopy(ptr) {
|
|
1600
1739
|
this.zeroCopyEventCalls += 1;
|
|
1601
|
-
const len = _nullishCoalesce(_optionalChain([this, 'access',
|
|
1740
|
+
const len = _nullishCoalesce(_optionalChain([this, 'access', _39 => _39.vm, 'access', _40 => _40.event_batch_len, 'optionalCall', _41 => _41()]), () => ( 0));
|
|
1602
1741
|
const words = this.readU32(ptr, len);
|
|
1603
1742
|
const events = decodeEventBatch(words);
|
|
1604
1743
|
this.eventsReceived += events.length;
|
|
1605
1744
|
this.maxEventsPerCall = Math.max(this.maxEventsPerCall, events.length);
|
|
1606
1745
|
return events;
|
|
1607
1746
|
}
|
|
1608
|
-
decodeBinary(words) {
|
|
1609
|
-
this.binaryEventCalls += 1;
|
|
1610
|
-
const events = decodeEventBatch(words);
|
|
1611
|
-
this.eventsReceived += events.length;
|
|
1612
|
-
this.maxEventsPerCall = Math.max(this.maxEventsPerCall, events.length);
|
|
1613
|
-
return events;
|
|
1614
|
-
}
|
|
1615
|
-
decodeJson(json) {
|
|
1616
|
-
this.jsonEventCalls += 1;
|
|
1617
|
-
this.eventsReceived += 1;
|
|
1618
|
-
this.maxEventsPerCall = Math.max(this.maxEventsPerCall, 1);
|
|
1619
|
-
return JSON.parse(json);
|
|
1620
|
-
}
|
|
1621
1747
|
memory() {
|
|
1622
|
-
const memory = _optionalChain([this, 'access',
|
|
1623
|
-
if (!_optionalChain([memory, 'optionalAccess',
|
|
1748
|
+
const memory = _optionalChain([this, 'access', _42 => _42.vm, 'access', _43 => _43.memory, 'optionalCall', _44 => _44()]);
|
|
1749
|
+
if (!_optionalChain([memory, 'optionalAccess', _45 => _45.buffer])) throw new Error("brass-runtime WASM memory is not available");
|
|
1624
1750
|
return memory;
|
|
1625
1751
|
}
|
|
1626
1752
|
readU32(ptr, len) {
|
|
@@ -1636,8 +1762,8 @@ var WasmPackFiberBridge = (_class11 = class {
|
|
|
1636
1762
|
new Uint32Array(this.memory().buffer, ptr, words.length).set(words);
|
|
1637
1763
|
}
|
|
1638
1764
|
readMetricsSnapshot() {
|
|
1639
|
-
const ptr = _nullishCoalesce(_optionalChain([this, 'access',
|
|
1640
|
-
const len = _nullishCoalesce(_optionalChain([this, 'access',
|
|
1765
|
+
const ptr = _nullishCoalesce(_optionalChain([this, 'access', _46 => _46.vm, 'access', _47 => _47.metrics_snapshot_ptr, 'optionalCall', _48 => _48()]), () => ( 0));
|
|
1766
|
+
const len = _nullishCoalesce(_optionalChain([this, 'access', _49 => _49.vm, 'access', _50 => _50.metrics_snapshot_len, 'optionalCall', _51 => _51()]), () => ( 0));
|
|
1641
1767
|
const view = this.readF64(ptr, len);
|
|
1642
1768
|
const out = {};
|
|
1643
1769
|
for (let i = 0; i < Math.min(view.length, VM_METRIC_NAMES.length); i++) {
|
|
@@ -1645,7 +1771,7 @@ var WasmPackFiberBridge = (_class11 = class {
|
|
|
1645
1771
|
}
|
|
1646
1772
|
return out;
|
|
1647
1773
|
}
|
|
1648
|
-
},
|
|
1774
|
+
}, _class12);
|
|
1649
1775
|
function loadWasmModule(modulePath) {
|
|
1650
1776
|
const mod = resolveWasmModule({ modulePath });
|
|
1651
1777
|
if (mod) return mod;
|
|
@@ -1669,7 +1795,7 @@ var WasmFiberRegistryBridge = class {
|
|
|
1669
1795
|
|
|
1670
1796
|
constructor() {
|
|
1671
1797
|
const mod = resolveWasmModule();
|
|
1672
|
-
const Ctor = _optionalChain([mod, 'optionalAccess',
|
|
1798
|
+
const Ctor = _optionalChain([mod, 'optionalAccess', _52 => _52.BrassWasmFiberRegistry]);
|
|
1673
1799
|
if (!Ctor) {
|
|
1674
1800
|
throw new Error("brass-runtime wasm fiber registry is not available. Run npm run build:wasm first.");
|
|
1675
1801
|
}
|
|
@@ -1768,7 +1894,7 @@ var DEFAULT_LANE_BUDGET2 = 64;
|
|
|
1768
1894
|
var DEFAULT_MAX_LANES2 = 256;
|
|
1769
1895
|
function resolveWasmReadyQueue() {
|
|
1770
1896
|
const mod = resolveWasmModule();
|
|
1771
|
-
return _nullishCoalesce(_optionalChain([mod, 'optionalAccess',
|
|
1897
|
+
return _nullishCoalesce(_optionalChain([mod, 'optionalAccess', _53 => _53.BrassWasmFiberReadyQueue]), () => ( null));
|
|
1772
1898
|
}
|
|
1773
1899
|
function decodePolicy(policy) {
|
|
1774
1900
|
switch (policy) {
|
|
@@ -1792,11 +1918,11 @@ function makeFiberReadyQueue(options = {}) {
|
|
|
1792
1918
|
}
|
|
1793
1919
|
throw new Error(`brass-runtime fiber ready queue engine must be 'ts' or 'wasm'; received '${String(requested)}'`);
|
|
1794
1920
|
}
|
|
1795
|
-
var WasmFiberReadyQueue = (
|
|
1796
|
-
|
|
1921
|
+
var WasmFiberReadyQueue = (_class13 = class {
|
|
1922
|
+
__init73() {this.engine = "wasm"}
|
|
1797
1923
|
|
|
1798
|
-
|
|
1799
|
-
constructor(Ctor, options) {;
|
|
1924
|
+
__init74() {this.laneCache = /* @__PURE__ */ new Map()}
|
|
1925
|
+
constructor(Ctor, options) {;_class13.prototype.__init73.call(this);_class13.prototype.__init74.call(this);
|
|
1800
1926
|
this.queue = new Ctor(
|
|
1801
1927
|
_nullishCoalesce(options.flushBudget, () => ( DEFAULT_FLUSH_BUDGET)),
|
|
1802
1928
|
_nullishCoalesce(options.microThreshold, () => ( DEFAULT_FLUSH_BUDGET * 2)),
|
|
@@ -1840,25 +1966,25 @@ var WasmFiberReadyQueue = (_class12 = class {
|
|
|
1840
1966
|
data: JSON.parse(this.queue.stats_json())
|
|
1841
1967
|
};
|
|
1842
1968
|
}
|
|
1843
|
-
},
|
|
1844
|
-
var TsFiberReadyQueue = (
|
|
1845
|
-
constructor(options) {;
|
|
1969
|
+
}, _class13);
|
|
1970
|
+
var TsFiberReadyQueue = (_class14 = class {
|
|
1971
|
+
constructor(options) {;_class14.prototype.__init75.call(this);_class14.prototype.__init76.call(this);_class14.prototype.__init77.call(this);_class14.prototype.__init78.call(this);_class14.prototype.__init79.call(this);_class14.prototype.__init80.call(this);_class14.prototype.__init81.call(this);_class14.prototype.__init82.call(this);_class14.prototype.__init83.call(this);_class14.prototype.__init84.call(this);_class14.prototype.__init85.call(this);_class14.prototype.__init86.call(this);_class14.prototype.__init87.call(this);
|
|
1846
1972
|
this.options = options;
|
|
1847
1973
|
}
|
|
1848
1974
|
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1975
|
+
__init75() {this.engine = "ts"}
|
|
1976
|
+
__init76() {this.lanes = /* @__PURE__ */ new Map()}
|
|
1977
|
+
__init77() {this.laneOrder = []}
|
|
1978
|
+
__init78() {this.rrIndex = 0}
|
|
1979
|
+
__init79() {this.rrRemaining = 0}
|
|
1980
|
+
__init80() {this.phase = "idle"}
|
|
1981
|
+
__init81() {this.totalLen = 0}
|
|
1982
|
+
__init82() {this.scheduledFlushes = 0}
|
|
1983
|
+
__init83() {this.completedFlushes = 0}
|
|
1984
|
+
__init84() {this.enqueuedFibers = 0}
|
|
1985
|
+
__init85() {this.executedFibers = 0}
|
|
1986
|
+
__init86() {this.droppedFibers = 0}
|
|
1987
|
+
__init87() {this.yieldedByBudget = 0}
|
|
1862
1988
|
enqueue(fiberId, tag) {
|
|
1863
1989
|
const lane = this.getOrCreateLane(inferLane2(tag));
|
|
1864
1990
|
this.enqueuedFibers += 1;
|
|
@@ -1985,7 +2111,7 @@ var TsFiberReadyQueue = (_class13 = class {
|
|
|
1985
2111
|
lane.executedFibers += 1;
|
|
1986
2112
|
return fiberId;
|
|
1987
2113
|
}
|
|
1988
|
-
},
|
|
2114
|
+
}, _class14);
|
|
1989
2115
|
function inferLane2(tag) {
|
|
1990
2116
|
const explicit = extractTaggedLane2(tag, "lane:");
|
|
1991
2117
|
if (explicit) return sanitizeLaneKey(explicit);
|
|
@@ -1997,9 +2123,9 @@ function inferLane2(tag) {
|
|
|
1997
2123
|
}
|
|
1998
2124
|
function extractTaggedLane2(tag, prefix) {
|
|
1999
2125
|
if (!tag.startsWith(prefix)) return void 0;
|
|
2000
|
-
const
|
|
2001
|
-
if (
|
|
2002
|
-
const value = tag.slice(prefix.length,
|
|
2126
|
+
const end = tag.indexOf("|", prefix.length);
|
|
2127
|
+
if (end < 0) return void 0;
|
|
2128
|
+
const value = tag.slice(prefix.length, end);
|
|
2003
2129
|
return value.length > 0 ? value : void 0;
|
|
2004
2130
|
}
|
|
2005
2131
|
function firstSeparatorIndex2(value) {
|
|
@@ -2083,7 +2209,7 @@ var WasmTimerWheelBridge = class {
|
|
|
2083
2209
|
};
|
|
2084
2210
|
function makeWasmTimerWheel(options) {
|
|
2085
2211
|
const mod = resolveWasmModule();
|
|
2086
|
-
const Ctor = _optionalChain([mod, 'optionalAccess',
|
|
2212
|
+
const Ctor = _optionalChain([mod, 'optionalAccess', _54 => _54.BrassWasmTimerWheel]);
|
|
2087
2213
|
if (!Ctor) throw new Error("brass-runtime wasm timer wheel is not available. Run npm run build:wasm first.");
|
|
2088
2214
|
return new WasmTimerWheelBridge(Ctor, options);
|
|
2089
2215
|
}
|
|
@@ -2094,8 +2220,8 @@ function toU64(value) {
|
|
|
2094
2220
|
// src/core/runtime/engine/WasmFiberEngine.ts
|
|
2095
2221
|
var DEFAULT_BUDGET = 4096;
|
|
2096
2222
|
var TIMER_KIND_HOST_ACTION = 1;
|
|
2097
|
-
var WasmFiberEngine = (
|
|
2098
|
-
constructor(runtime, options = {}) {;
|
|
2223
|
+
var WasmFiberEngine = (_class15 = class {
|
|
2224
|
+
constructor(runtime, options = {}) {;_class15.prototype.__init88.call(this);_class15.prototype.__init89.call(this);_class15.prototype.__init90.call(this);_class15.prototype.__init91.call(this);_class15.prototype.__init92.call(this);_class15.prototype.__init93.call(this);_class15.prototype.__init94.call(this);_class15.prototype.__init95.call(this);_class15.prototype.__init96.call(this);_class15.prototype.__init97.call(this);_class15.prototype.__init98.call(this);
|
|
2099
2225
|
this.runtime = runtime;
|
|
2100
2226
|
this.bridge = _nullishCoalesce(options.bridge, () => ( new WasmPackFiberBridge(options.modulePath)));
|
|
2101
2227
|
if (this.bridge.kind !== "wasm") {
|
|
@@ -2103,24 +2229,24 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2103
2229
|
}
|
|
2104
2230
|
this.kind = this.bridge.kind;
|
|
2105
2231
|
this.fiberRegistry = new WasmFiberRegistryBridge();
|
|
2106
|
-
this.readyQueue = makeFiberReadyQueue({ engine: "wasm" });
|
|
2232
|
+
this.readyQueue = makeFiberReadyQueue({ engine: "wasm", ...options.readyQueue });
|
|
2107
2233
|
this.timerWheel = makeWasmTimerWheel({ onExpired: (events) => this.onTimerExpired(events) });
|
|
2108
2234
|
}
|
|
2109
2235
|
|
|
2110
2236
|
|
|
2111
2237
|
|
|
2112
2238
|
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2239
|
+
__init88() {this.startedFibers = 0}
|
|
2240
|
+
__init89() {this.runningFibers = 0}
|
|
2241
|
+
__init90() {this.suspendedFibers = 0}
|
|
2242
|
+
__init91() {this.completedFibers = 0}
|
|
2243
|
+
__init92() {this.failedFibers = 0}
|
|
2244
|
+
__init93() {this.interruptedFibers = 0}
|
|
2245
|
+
__init94() {this.pendingHostEffects = 0}
|
|
2246
|
+
__init95() {this.readyDrainScheduled = false}
|
|
2247
|
+
__init96() {this.readyDraining = false}
|
|
2248
|
+
__init97() {this.states = /* @__PURE__ */ new Map()}
|
|
2249
|
+
__init98() {this.pendingResumes = /* @__PURE__ */ new Map()}
|
|
2124
2250
|
|
|
2125
2251
|
|
|
2126
2252
|
fork(effect, scopeId) {
|
|
@@ -2133,8 +2259,8 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2133
2259
|
this.runtime,
|
|
2134
2260
|
(id) => this.driveById(id),
|
|
2135
2261
|
(id, reason) => this.interruptById(id, reason),
|
|
2136
|
-
(id) => _optionalChain([this, 'access',
|
|
2137
|
-
(id) => _optionalChain([this, 'access',
|
|
2262
|
+
(id) => _optionalChain([this, 'access', _55 => _55.fiberRegistry, 'optionalAccess', _56 => _56.addJoiner, 'call', _57 => _57(id)]),
|
|
2263
|
+
(id) => _optionalChain([this, 'access', _58 => _58.fiberRegistry, 'optionalAccess', _59 => _59.markQueued, 'call', _60 => _60(id)]),
|
|
2138
2264
|
(id, label) => this.schedulerDropped(id, label),
|
|
2139
2265
|
(id, label) => this.enqueueFiberById(id, label)
|
|
2140
2266
|
);
|
|
@@ -2152,7 +2278,7 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2152
2278
|
hostActionToken: 0
|
|
2153
2279
|
};
|
|
2154
2280
|
this.states.set(fiberId, state);
|
|
2155
|
-
_optionalChain([this, 'access',
|
|
2281
|
+
_optionalChain([this, 'access', _61 => _61.fiberRegistry, 'optionalAccess', _62 => _62.registerFiber, 'call', _63 => _63(fiberId, void 0, scopeId)]);
|
|
2156
2282
|
this.startedFibers += 1;
|
|
2157
2283
|
this.runningFibers += 1;
|
|
2158
2284
|
return handle;
|
|
@@ -2193,17 +2319,17 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2193
2319
|
staleReads: hostStaleReads
|
|
2194
2320
|
},
|
|
2195
2321
|
wasm: this.bridge.stats(),
|
|
2196
|
-
fiberRegistry: _optionalChain([this, 'access',
|
|
2322
|
+
fiberRegistry: _optionalChain([this, 'access', _64 => _64.fiberRegistry, 'optionalAccess', _65 => _65.stats, 'call', _66 => _66()]),
|
|
2197
2323
|
readyQueue: this.readyQueue.stats(),
|
|
2198
|
-
timerWheel: _optionalChain([this, 'access',
|
|
2324
|
+
timerWheel: _optionalChain([this, 'access', _67 => _67.timerWheel, 'optionalAccess', _68 => _68.stats, 'call', _69 => _69()])
|
|
2199
2325
|
};
|
|
2200
2326
|
}
|
|
2201
2327
|
async shutdown() {
|
|
2202
2328
|
for (const state of Array.from(this.states.values())) {
|
|
2203
|
-
this.interruptState(state, Cause.interrupt());
|
|
2329
|
+
this.interruptState(state, _chunkMVGUEJ5Zcjs.Cause.interrupt());
|
|
2204
2330
|
}
|
|
2205
2331
|
this.readyQueue.clear();
|
|
2206
|
-
_optionalChain([this, 'access',
|
|
2332
|
+
_optionalChain([this, 'access', _70 => _70.timerWheel, 'optionalAccess', _71 => _71.dispose, 'call', _72 => _72()]);
|
|
2207
2333
|
}
|
|
2208
2334
|
scheduleWakeup(fiberId) {
|
|
2209
2335
|
const state = this.states.get(fiberId);
|
|
@@ -2277,7 +2403,7 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2277
2403
|
const state = this.states.get(fiberId);
|
|
2278
2404
|
if (!state || state.completed) return;
|
|
2279
2405
|
state.handle.markDequeued();
|
|
2280
|
-
_optionalChain([this, 'access',
|
|
2406
|
+
_optionalChain([this, 'access', _73 => _73.fiberRegistry, 'optionalAccess', _74 => _74.markRunning, 'call', _75 => _75(fiberId)]);
|
|
2281
2407
|
const initialEvents = this.consumePendingResume(state);
|
|
2282
2408
|
withCurrentFiber(state.handle, () => this.drive(state, initialEvents));
|
|
2283
2409
|
}
|
|
@@ -2286,9 +2412,9 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2286
2412
|
if (!pending) return void 0;
|
|
2287
2413
|
this.pendingResumes.delete(state.fiberId);
|
|
2288
2414
|
if (pending.kind === "value") {
|
|
2289
|
-
return _nullishCoalesce(_optionalChain([this, 'access',
|
|
2415
|
+
return _nullishCoalesce(_optionalChain([this, 'access', _76 => _76.bridge, 'access', _77 => _77.provideValueBatch, 'optionalCall', _78 => _78(state.fiberId, pending.ref, DEFAULT_BUDGET)]), () => ( [this.bridge.provideValue(state.fiberId, pending.ref)]));
|
|
2290
2416
|
}
|
|
2291
|
-
return _nullishCoalesce(_optionalChain([this, 'access',
|
|
2417
|
+
return _nullishCoalesce(_optionalChain([this, 'access', _79 => _79.bridge, 'access', _80 => _80.provideErrorBatch, 'optionalCall', _81 => _81(state.fiberId, pending.ref, DEFAULT_BUDGET)]), () => ( [this.bridge.provideError(state.fiberId, pending.ref)]));
|
|
2292
2418
|
}
|
|
2293
2419
|
drive(state, initialEvents) {
|
|
2294
2420
|
if (state.completed) return;
|
|
@@ -2299,7 +2425,7 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2299
2425
|
while (!state.completed && budget-- > 0) {
|
|
2300
2426
|
try {
|
|
2301
2427
|
if (events.length === 0) {
|
|
2302
|
-
const next = _nullishCoalesce(_optionalChain([this, 'access',
|
|
2428
|
+
const next = _nullishCoalesce(_optionalChain([this, 'access', _82 => _82.bridge, 'access', _83 => _83.driveBatch, 'optionalCall', _84 => _84(state.fiberId, budget + 1)]), () => ( [this.bridge.poll(state.fiberId)]));
|
|
2303
2429
|
events.push(...next);
|
|
2304
2430
|
if (events.length === 0) events.push({ kind: "Continue", fiberId: state.fiberId });
|
|
2305
2431
|
}
|
|
@@ -2325,9 +2451,9 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2325
2451
|
const fn = state.registry.get(event.fnRef);
|
|
2326
2452
|
try {
|
|
2327
2453
|
const valueRef = state.registry.register(fn(this.runtime.env));
|
|
2328
|
-
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access',
|
|
2454
|
+
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access', _85 => _85.bridge, 'access', _86 => _86.provideValueBatch, 'optionalCall', _87 => _87(state.fiberId, valueRef, budget + 1)]), () => ( [this.bridge.provideValue(state.fiberId, valueRef)])));
|
|
2329
2455
|
} catch (error) {
|
|
2330
|
-
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access',
|
|
2456
|
+
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access', _88 => _88.bridge, 'access', _89 => _89.provideErrorBatch, 'optionalCall', _90 => _90(state.fiberId, state.registry.register(error), budget + 1)]), () => ( [this.bridge.provideError(state.fiberId, state.registry.register(error))])));
|
|
2331
2457
|
}
|
|
2332
2458
|
continue;
|
|
2333
2459
|
}
|
|
@@ -2337,9 +2463,9 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2337
2463
|
try {
|
|
2338
2464
|
const next = fn(value);
|
|
2339
2465
|
const patch = state.builder.append(next);
|
|
2340
|
-
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access',
|
|
2466
|
+
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access', _91 => _91.bridge, 'access', _92 => _92.provideEffectBatch, 'optionalCall', _93 => _93(state.fiberId, patch.root, patch.nodes, budget + 1)]), () => ( [this.bridge.provideEffect(state.fiberId, patch.root, patch.nodes)])));
|
|
2341
2467
|
} catch (error) {
|
|
2342
|
-
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access',
|
|
2468
|
+
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access', _94 => _94.bridge, 'access', _95 => _95.provideErrorBatch, 'optionalCall', _96 => _96(state.fiberId, state.registry.register(error), budget + 1)]), () => ( [this.bridge.provideError(state.fiberId, state.registry.register(error))])));
|
|
2343
2469
|
}
|
|
2344
2470
|
continue;
|
|
2345
2471
|
}
|
|
@@ -2349,9 +2475,9 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2349
2475
|
try {
|
|
2350
2476
|
const next = fn(errorValue);
|
|
2351
2477
|
const patch = state.builder.append(next);
|
|
2352
|
-
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access',
|
|
2478
|
+
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access', _97 => _97.bridge, 'access', _98 => _98.provideEffectBatch, 'optionalCall', _99 => _99(state.fiberId, patch.root, patch.nodes, budget + 1)]), () => ( [this.bridge.provideEffect(state.fiberId, patch.root, patch.nodes)])));
|
|
2353
2479
|
} catch (error) {
|
|
2354
|
-
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access',
|
|
2480
|
+
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access', _100 => _100.bridge, 'access', _101 => _101.provideErrorBatch, 'optionalCall', _102 => _102(state.fiberId, state.registry.register(error), budget + 1)]), () => ( [this.bridge.provideError(state.fiberId, state.registry.register(error))])));
|
|
2355
2481
|
}
|
|
2356
2482
|
continue;
|
|
2357
2483
|
}
|
|
@@ -2361,9 +2487,9 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2361
2487
|
try {
|
|
2362
2488
|
const next = fn(value);
|
|
2363
2489
|
const patch = state.builder.append(next);
|
|
2364
|
-
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access',
|
|
2490
|
+
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access', _103 => _103.bridge, 'access', _104 => _104.provideEffectBatch, 'optionalCall', _105 => _105(state.fiberId, patch.root, patch.nodes, budget + 1)]), () => ( [this.bridge.provideEffect(state.fiberId, patch.root, patch.nodes)])));
|
|
2365
2491
|
} catch (error) {
|
|
2366
|
-
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access',
|
|
2492
|
+
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access', _106 => _106.bridge, 'access', _107 => _107.provideErrorBatch, 'optionalCall', _108 => _108(state.fiberId, state.registry.register(error), budget + 1)]), () => ( [this.bridge.provideError(state.fiberId, state.registry.register(error))])));
|
|
2367
2493
|
}
|
|
2368
2494
|
continue;
|
|
2369
2495
|
}
|
|
@@ -2371,9 +2497,9 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2371
2497
|
const effect = state.registry.get(event.effectRef);
|
|
2372
2498
|
try {
|
|
2373
2499
|
const child = this.runtime.fork(effect, event.scopeId);
|
|
2374
|
-
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access',
|
|
2500
|
+
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access', _109 => _109.bridge, 'access', _110 => _110.provideValueBatch, 'optionalCall', _111 => _111(state.fiberId, state.registry.register(child), budget + 1)]), () => ( [this.bridge.provideValue(state.fiberId, state.registry.register(child))])));
|
|
2375
2501
|
} catch (error) {
|
|
2376
|
-
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access',
|
|
2502
|
+
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access', _112 => _112.bridge, 'access', _113 => _113.provideErrorBatch, 'optionalCall', _114 => _114(state.fiberId, state.registry.register(error), budget + 1)]), () => ( [this.bridge.provideError(state.fiberId, state.registry.register(error))])));
|
|
2377
2503
|
}
|
|
2378
2504
|
continue;
|
|
2379
2505
|
}
|
|
@@ -2387,7 +2513,7 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2387
2513
|
}
|
|
2388
2514
|
}
|
|
2389
2515
|
} catch (error) {
|
|
2390
|
-
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access',
|
|
2516
|
+
events.unshift(..._nullishCoalesce(_optionalChain([this, 'access', _115 => _115.bridge, 'access', _116 => _116.provideErrorBatch, 'optionalCall', _117 => _117(state.fiberId, state.registry.register(error), budget + 1)]), () => ( [this.bridge.provideError(state.fiberId, state.registry.register(error))])));
|
|
2391
2517
|
}
|
|
2392
2518
|
}
|
|
2393
2519
|
if (!state.completed) this.enqueueFiber(state, "budget-yield");
|
|
@@ -2443,7 +2569,7 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2443
2569
|
}
|
|
2444
2570
|
};
|
|
2445
2571
|
state.pendingCleanups.add(cancelCleanup);
|
|
2446
|
-
state.handle.addFinalizer(() => _optionalChain([cancelCleanup, 'optionalCall',
|
|
2572
|
+
state.handle.addFinalizer(() => _optionalChain([cancelCleanup, 'optionalCall', _118 => _118()]));
|
|
2447
2573
|
}
|
|
2448
2574
|
} catch (error) {
|
|
2449
2575
|
cleanup();
|
|
@@ -2460,7 +2586,7 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2460
2586
|
const deadlineAt = action.timeoutMs === void 0 ? void 0 : Date.now() + action.timeoutMs;
|
|
2461
2587
|
const cleanup = () => {
|
|
2462
2588
|
state.pendingCleanups.delete(cleanup);
|
|
2463
|
-
_optionalChain([this, 'access',
|
|
2589
|
+
_optionalChain([this, 'access', _119 => _119.timerWheel, 'optionalAccess', _120 => _120.cancel, 'call', _121 => _121(state.deadlineTimerId)]);
|
|
2464
2590
|
if (state.hostActionToken === token) state.deadlineTimerId = void 0;
|
|
2465
2591
|
};
|
|
2466
2592
|
state.pendingCleanups.add(cleanup);
|
|
@@ -2521,15 +2647,32 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2521
2647
|
return;
|
|
2522
2648
|
}
|
|
2523
2649
|
const cause = exit.cause;
|
|
2524
|
-
if (cause
|
|
2650
|
+
if (_chunkMVGUEJ5Zcjs.Cause.isInterruptedOnly(cause)) {
|
|
2525
2651
|
this.interruptState(state, cause);
|
|
2526
2652
|
return;
|
|
2527
2653
|
}
|
|
2528
|
-
if (cause
|
|
2529
|
-
|
|
2530
|
-
|
|
2654
|
+
if (_chunkMVGUEJ5Zcjs.Cause.isFailureOnly(cause)) {
|
|
2655
|
+
const failure = _chunkMVGUEJ5Zcjs.Cause.firstFailure(cause);
|
|
2656
|
+
if (failure._tag === "Some") {
|
|
2657
|
+
this.resumeWithError(state, failure.value);
|
|
2658
|
+
return;
|
|
2659
|
+
}
|
|
2531
2660
|
}
|
|
2532
|
-
this.
|
|
2661
|
+
this.completeCause(state, cause);
|
|
2662
|
+
}
|
|
2663
|
+
completeCause(state, cause) {
|
|
2664
|
+
if (state.completed) return;
|
|
2665
|
+
state.completed = true;
|
|
2666
|
+
const interrupted = _chunkMVGUEJ5Zcjs.Cause.isInterruptedOnly(cause);
|
|
2667
|
+
state.status = interrupted ? "interrupted" : "failed";
|
|
2668
|
+
_optionalChain([this, 'access', _122 => _122.fiberRegistry, 'optionalAccess', _123 => _123.markDone, 'call', _124 => _124(state.fiberId, interrupted ? "interrupted" : "failed")]);
|
|
2669
|
+
if (interrupted) {
|
|
2670
|
+
this.interruptedFibers += 1;
|
|
2671
|
+
} else {
|
|
2672
|
+
this.failedFibers += 1;
|
|
2673
|
+
}
|
|
2674
|
+
this.cleanupState(state);
|
|
2675
|
+
state.handle.complete(_chunkMVGUEJ5Zcjs.Exit.failCause(cause));
|
|
2533
2676
|
}
|
|
2534
2677
|
resumeWithValue(state, value) {
|
|
2535
2678
|
this.pendingResumes.set(state.fiberId, { kind: "value", ref: state.registry.register(value) });
|
|
@@ -2557,14 +2700,14 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2557
2700
|
if (state.completed) return;
|
|
2558
2701
|
if (!state.controller.signal.aborted) state.controller.abort(reason);
|
|
2559
2702
|
for (const cleanup of Array.from(state.pendingCleanups)) cleanup();
|
|
2560
|
-
const events = _nullishCoalesce(_optionalChain([this, 'access',
|
|
2703
|
+
const events = _nullishCoalesce(_optionalChain([this, 'access', _125 => _125.bridge, 'access', _126 => _126.interruptBatch, 'optionalCall', _127 => _127(state.fiberId, state.registry.register(reason), DEFAULT_BUDGET)]), () => ( [this.bridge.interrupt(state.fiberId, state.registry.register(reason))]));
|
|
2561
2704
|
this.drive(state, events);
|
|
2562
2705
|
}
|
|
2563
2706
|
markSuspended(state, reason) {
|
|
2564
2707
|
if (state.status !== "suspended") {
|
|
2565
2708
|
this.suspendedFibers += 1;
|
|
2566
2709
|
state.status = "suspended";
|
|
2567
|
-
_optionalChain([this, 'access',
|
|
2710
|
+
_optionalChain([this, 'access', _128 => _128.fiberRegistry, 'optionalAccess', _129 => _129.markSuspended, 'call', _130 => _130(state.fiberId)]);
|
|
2568
2711
|
state.handle.setEngineStatus("suspended");
|
|
2569
2712
|
state.handle.emit({ type: "fiber.suspend", fiberId: state.fiberId, reason });
|
|
2570
2713
|
}
|
|
@@ -2573,7 +2716,7 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2573
2716
|
if (state.status === "suspended") {
|
|
2574
2717
|
this.suspendedFibers = Math.max(0, this.suspendedFibers - 1);
|
|
2575
2718
|
state.status = "running";
|
|
2576
|
-
_optionalChain([this, 'access',
|
|
2719
|
+
_optionalChain([this, 'access', _131 => _131.fiberRegistry, 'optionalAccess', _132 => _132.markRunning, 'call', _133 => _133(state.fiberId)]);
|
|
2577
2720
|
state.handle.setEngineStatus("running");
|
|
2578
2721
|
state.handle.emit({ type: "fiber.resume", fiberId: state.fiberId });
|
|
2579
2722
|
}
|
|
@@ -2582,7 +2725,7 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2582
2725
|
if (state.completed) return;
|
|
2583
2726
|
state.completed = true;
|
|
2584
2727
|
state.status = "done";
|
|
2585
|
-
_optionalChain([this, 'access',
|
|
2728
|
+
_optionalChain([this, 'access', _134 => _134.fiberRegistry, 'optionalAccess', _135 => _135.markDone, 'call', _136 => _136(state.fiberId, "done")]);
|
|
2586
2729
|
this.completedFibers += 1;
|
|
2587
2730
|
this.cleanupState(state);
|
|
2588
2731
|
state.handle.succeed(value);
|
|
@@ -2591,7 +2734,7 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2591
2734
|
if (state.completed) return;
|
|
2592
2735
|
state.completed = true;
|
|
2593
2736
|
state.status = "failed";
|
|
2594
|
-
_optionalChain([this, 'access',
|
|
2737
|
+
_optionalChain([this, 'access', _137 => _137.fiberRegistry, 'optionalAccess', _138 => _138.markDone, 'call', _139 => _139(state.fiberId, "failed")]);
|
|
2595
2738
|
this.failedFibers += 1;
|
|
2596
2739
|
this.cleanupState(state);
|
|
2597
2740
|
state.handle.fail(error);
|
|
@@ -2600,7 +2743,7 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2600
2743
|
if (state.completed) return;
|
|
2601
2744
|
state.completed = true;
|
|
2602
2745
|
state.status = "failed";
|
|
2603
|
-
_optionalChain([this, 'access',
|
|
2746
|
+
_optionalChain([this, 'access', _140 => _140.fiberRegistry, 'optionalAccess', _141 => _141.markDone, 'call', _142 => _142(state.fiberId, "failed")]);
|
|
2604
2747
|
this.failedFibers += 1;
|
|
2605
2748
|
this.cleanupState(state);
|
|
2606
2749
|
state.handle.die(defect);
|
|
@@ -2609,7 +2752,7 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2609
2752
|
if (state.completed) return;
|
|
2610
2753
|
state.completed = true;
|
|
2611
2754
|
state.status = "interrupted";
|
|
2612
|
-
_optionalChain([this, 'access',
|
|
2755
|
+
_optionalChain([this, 'access', _143 => _143.fiberRegistry, 'optionalAccess', _144 => _144.markDone, 'call', _145 => _145(state.fiberId, "interrupted")]);
|
|
2613
2756
|
this.interruptedFibers += 1;
|
|
2614
2757
|
this.cleanupState(state);
|
|
2615
2758
|
state.handle.interrupted();
|
|
@@ -2617,34 +2760,34 @@ var WasmFiberEngine = (_class14 = class {
|
|
|
2617
2760
|
cleanupState(state) {
|
|
2618
2761
|
this.runningFibers = Math.max(0, this.runningFibers - 1);
|
|
2619
2762
|
if (state.status === "suspended") this.suspendedFibers = Math.max(0, this.suspendedFibers - 1);
|
|
2620
|
-
_optionalChain([this, 'access',
|
|
2763
|
+
_optionalChain([this, 'access', _146 => _146.timerWheel, 'optionalAccess', _147 => _147.cancel, 'call', _148 => _148(state.deadlineTimerId)]);
|
|
2621
2764
|
state.deadlineTimerId = void 0;
|
|
2622
2765
|
for (const cleanup of Array.from(state.pendingCleanups)) cleanup();
|
|
2623
2766
|
state.pendingCleanups.clear();
|
|
2624
2767
|
this.pendingResumes.delete(state.fiberId);
|
|
2625
2768
|
this.bridge.dropFiber(state.fiberId);
|
|
2626
|
-
_optionalChain([this, 'access',
|
|
2769
|
+
_optionalChain([this, 'access', _149 => _149.fiberRegistry, 'optionalAccess', _150 => _150.dropFiber, 'call', _151 => _151(state.fiberId)]);
|
|
2627
2770
|
state.registry.clear();
|
|
2628
2771
|
this.states.delete(state.fiberId);
|
|
2629
2772
|
}
|
|
2630
|
-
},
|
|
2773
|
+
}, _class15);
|
|
2631
2774
|
|
|
2632
2775
|
// src/core/runtime/capabilities.ts
|
|
2633
2776
|
function runtimeCapabilities() {
|
|
2634
2777
|
const mod = resolveWasmModule();
|
|
2635
2778
|
return {
|
|
2636
2779
|
wasmAvailable: !!mod,
|
|
2637
|
-
wasmFiberEngine: typeof _optionalChain([mod, 'optionalAccess',
|
|
2638
|
-
wasmRingBuffer: typeof _optionalChain([mod, 'optionalAccess',
|
|
2639
|
-
wasmScheduler: typeof _optionalChain([mod, 'optionalAccess',
|
|
2640
|
-
wasmFiberRegistry: typeof _optionalChain([mod, 'optionalAccess',
|
|
2641
|
-
wasmFiberReadyQueue: typeof _optionalChain([mod, 'optionalAccess',
|
|
2780
|
+
wasmFiberEngine: typeof _optionalChain([mod, 'optionalAccess', _152 => _152.BrassWasmVm]) === "function",
|
|
2781
|
+
wasmRingBuffer: typeof _optionalChain([mod, 'optionalAccess', _153 => _153.BrassWasmRingBuffer]) === "function",
|
|
2782
|
+
wasmScheduler: typeof _optionalChain([mod, 'optionalAccess', _154 => _154.BrassWasmSchedulerStateMachine]) === "function",
|
|
2783
|
+
wasmFiberRegistry: typeof _optionalChain([mod, 'optionalAccess', _155 => _155.BrassWasmFiberRegistry]) === "function",
|
|
2784
|
+
wasmFiberReadyQueue: typeof _optionalChain([mod, 'optionalAccess', _156 => _156.BrassWasmFiberReadyQueue]) === "function",
|
|
2642
2785
|
wasmBinaryAbi: hasBinaryVmAbi(mod),
|
|
2643
|
-
wasmStreamChunks: typeof _optionalChain([mod, 'optionalAccess',
|
|
2786
|
+
wasmStreamChunks: typeof _optionalChain([mod, 'optionalAccess', _157 => _157.BrassWasmChunkBuffer]) === "function"
|
|
2644
2787
|
};
|
|
2645
2788
|
}
|
|
2646
2789
|
function hasBinaryVmAbi(mod) {
|
|
2647
|
-
const Ctor = _optionalChain([mod, 'optionalAccess',
|
|
2790
|
+
const Ctor = _optionalChain([mod, 'optionalAccess', _158 => _158.BrassWasmVm]);
|
|
2648
2791
|
if (typeof Ctor !== "function") return false;
|
|
2649
2792
|
try {
|
|
2650
2793
|
const vm = new Ctor();
|
|
@@ -2654,6 +2797,21 @@ function hasBinaryVmAbi(mod) {
|
|
|
2654
2797
|
}
|
|
2655
2798
|
}
|
|
2656
2799
|
|
|
2800
|
+
// src/core/runtime/clock.ts
|
|
2801
|
+
var liveClock = {
|
|
2802
|
+
now: () => {
|
|
2803
|
+
if (typeof performance !== "undefined" && typeof performance.now === "function") {
|
|
2804
|
+
return performance.now();
|
|
2805
|
+
}
|
|
2806
|
+
return Date.now();
|
|
2807
|
+
},
|
|
2808
|
+
setTimeout: (task, ms) => setTimeout(task, Math.max(0, Math.floor(ms))),
|
|
2809
|
+
clearTimeout: (timer) => clearTimeout(timer)
|
|
2810
|
+
};
|
|
2811
|
+
function runtimeClockFromEnv(env) {
|
|
2812
|
+
return _nullishCoalesce(_optionalChain([env, 'optionalAccess', _159 => _159.brass, 'optionalAccess', _160 => _160.clock]), () => ( liveClock));
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2657
2815
|
// src/core/runtime/runtime.ts
|
|
2658
2816
|
var NoopHooks = {
|
|
2659
2817
|
emit() {
|
|
@@ -2666,6 +2824,12 @@ function normalizeRuntimeEngineMode(value) {
|
|
|
2666
2824
|
function unreachableEngine(value) {
|
|
2667
2825
|
throw new Error(`brass-runtime unsupported engine '${String(value)}'`);
|
|
2668
2826
|
}
|
|
2827
|
+
var runtimeOptionsSchema = _chunkCZIVE6NTcjs.Schema.object({
|
|
2828
|
+
env: _chunkCZIVE6NTcjs.Schema.any(),
|
|
2829
|
+
lane: _chunkCZIVE6NTcjs.Schema.string({ minLength: 1 }).optional(),
|
|
2830
|
+
inferLane: _chunkCZIVE6NTcjs.Schema.boolean().optional(),
|
|
2831
|
+
engine: _chunkCZIVE6NTcjs.Schema.enum(["ts", "wasm"]).optional()
|
|
2832
|
+
}, { unknownKeys: "passthrough" });
|
|
2669
2833
|
var Runtime = class _Runtime {
|
|
2670
2834
|
|
|
2671
2835
|
|
|
@@ -2681,6 +2845,7 @@ var Runtime = class _Runtime {
|
|
|
2681
2845
|
// opcional: registry para observabilidad
|
|
2682
2846
|
|
|
2683
2847
|
constructor(args) {
|
|
2848
|
+
_chunkCZIVE6NTcjs.parseConfig.call(void 0, "RuntimeOptions", runtimeOptionsSchema, args);
|
|
2684
2849
|
this.env = args.env;
|
|
2685
2850
|
this.scheduler = _nullishCoalesce(args.scheduler, () => ( globalScheduler));
|
|
2686
2851
|
this.lane = args.lane;
|
|
@@ -2733,7 +2898,7 @@ var Runtime = class _Runtime {
|
|
|
2733
2898
|
}
|
|
2734
2899
|
resolveFiberLane(parent) {
|
|
2735
2900
|
if (this.lane !== void 0) return this.lane;
|
|
2736
|
-
const parentLane = _optionalChain([parent, 'optionalAccess',
|
|
2901
|
+
const parentLane = _optionalChain([parent, 'optionalAccess', _161 => _161.lane]);
|
|
2737
2902
|
if (typeof parentLane === "string" && parentLane.length > 0) return parentLane;
|
|
2738
2903
|
if (!this.inferLane) return void 0;
|
|
2739
2904
|
return inferCallerLaneFromStack(void 0, "runtime");
|
|
@@ -2742,11 +2907,15 @@ var Runtime = class _Runtime {
|
|
|
2742
2907
|
if (this.hooks === NoopHooks) return;
|
|
2743
2908
|
const f = getCurrentFiber();
|
|
2744
2909
|
const ctx = {
|
|
2745
|
-
fiberId: _optionalChain([f, 'optionalAccess',
|
|
2746
|
-
scopeId: _optionalChain([f, 'optionalAccess',
|
|
2910
|
+
fiberId: _optionalChain([f, 'optionalAccess', _162 => _162.id]),
|
|
2911
|
+
scopeId: _optionalChain([f, 'optionalAccess', _163 => _163.scopeId]),
|
|
2747
2912
|
// ✅ FIX: era f?.scope
|
|
2748
|
-
traceId: _optionalChain([f, 'optionalAccess',
|
|
2749
|
-
spanId: _optionalChain([f, 'optionalAccess',
|
|
2913
|
+
traceId: _optionalChain([f, 'optionalAccess', _164 => _164.fiberContext, 'optionalAccess', _165 => _165.trace, 'optionalAccess', _166 => _166.traceId]),
|
|
2914
|
+
spanId: _optionalChain([f, 'optionalAccess', _167 => _167.fiberContext, 'optionalAccess', _168 => _168.trace, 'optionalAccess', _169 => _169.spanId]),
|
|
2915
|
+
parentSpanId: _optionalChain([f, 'optionalAccess', _170 => _170.fiberContext, 'optionalAccess', _171 => _171.trace, 'optionalAccess', _172 => _172.parentSpanId]),
|
|
2916
|
+
traceState: _optionalChain([f, 'optionalAccess', _173 => _173.fiberContext, 'optionalAccess', _174 => _174.trace, 'optionalAccess', _175 => _175.traceState]),
|
|
2917
|
+
baggage: _optionalChain([f, 'optionalAccess', _176 => _176.fiberContext, 'optionalAccess', _177 => _177.trace, 'optionalAccess', _178 => _178.baggage]),
|
|
2918
|
+
sampled: _optionalChain([f, 'optionalAccess', _179 => _179.fiberContext, 'optionalAccess', _180 => _180.trace, 'optionalAccess', _181 => _181.sampled])
|
|
2750
2919
|
};
|
|
2751
2920
|
this.hooks.emit(ev, ctx);
|
|
2752
2921
|
}
|
|
@@ -2760,7 +2929,7 @@ var Runtime = class _Runtime {
|
|
|
2760
2929
|
if (lane !== void 0) fiber.lane = lane;
|
|
2761
2930
|
if (scopeId !== void 0) fiber.scopeId = scopeId;
|
|
2762
2931
|
this.forkPolicy.initChild(fiber, parent, scopeId);
|
|
2763
|
-
_optionalChain([fiber, 'access',
|
|
2932
|
+
_optionalChain([fiber, 'access', _182 => _182.schedule, 'optionalCall', _183 => _183("initial-step")]);
|
|
2764
2933
|
return fiber;
|
|
2765
2934
|
}
|
|
2766
2935
|
stats() {
|
|
@@ -2771,37 +2940,61 @@ var Runtime = class _Runtime {
|
|
|
2771
2940
|
return runtimeCapabilities();
|
|
2772
2941
|
}
|
|
2773
2942
|
shutdown() {
|
|
2774
|
-
return _optionalChain([this, 'access',
|
|
2943
|
+
return _optionalChain([this, 'access', _184 => _184.fiberEngine, 'access', _185 => _185.shutdown, 'optionalCall', _186 => _186()]);
|
|
2775
2944
|
}
|
|
2776
2945
|
unsafeRunAsync(effect, cb) {
|
|
2946
|
+
if (this.tryRunNativeTopLevel(effect, cb)) return;
|
|
2777
2947
|
const fiber = this.fork(effect);
|
|
2778
2948
|
fiber.join(cb);
|
|
2779
2949
|
}
|
|
2780
2950
|
toPromise(effect) {
|
|
2781
2951
|
return new Promise((resolve, reject) => {
|
|
2782
|
-
const
|
|
2783
|
-
|
|
2784
|
-
|
|
2952
|
+
const complete = (exit) => {
|
|
2953
|
+
if (exit._tag === "Success") {
|
|
2954
|
+
resolve(exit.value);
|
|
2955
|
+
return;
|
|
2956
|
+
}
|
|
2957
|
+
const failure = _chunkMVGUEJ5Zcjs.Cause.firstFailure(exit.cause);
|
|
2958
|
+
if (failure._tag === "Some") reject(failure.value);
|
|
2785
2959
|
else {
|
|
2786
|
-
const
|
|
2787
|
-
if (
|
|
2788
|
-
|
|
2789
|
-
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
|
+
}
|
|
2790
2968
|
}
|
|
2969
|
+
};
|
|
2970
|
+
if (this.tryRunNativeTopLevel(effect, complete)) return;
|
|
2971
|
+
const fiber = this.fork(effect);
|
|
2972
|
+
fiber.join((exit) => {
|
|
2973
|
+
complete(exit);
|
|
2791
2974
|
});
|
|
2792
2975
|
});
|
|
2793
2976
|
}
|
|
2977
|
+
tryRunNativeTopLevel(effect, cb) {
|
|
2978
|
+
if (this.hooks !== NoopHooks) return false;
|
|
2979
|
+
if (getCurrentFiber() !== null) return false;
|
|
2980
|
+
if (this.scheduler !== globalScheduler) return false;
|
|
2981
|
+
if (this.lane !== void 0 || this.inferLane) return false;
|
|
2982
|
+
if (this.engineMode !== "ts") return false;
|
|
2983
|
+
new NativeTopLevelRunner(this, effect, cb).start();
|
|
2984
|
+
return true;
|
|
2985
|
+
}
|
|
2794
2986
|
// helper: correr un efecto y “tirar” el resultado
|
|
2795
2987
|
unsafeRun(effect) {
|
|
2796
2988
|
this.unsafeRunAsync(effect, () => {
|
|
2797
2989
|
});
|
|
2798
2990
|
}
|
|
2799
2991
|
delay(ms, eff) {
|
|
2800
|
-
return asyncEffect((_env, cb) => {
|
|
2801
|
-
const
|
|
2992
|
+
return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (_env, cb) => {
|
|
2993
|
+
const clock = runtimeClockFromEnv(this.env);
|
|
2994
|
+
const handle = clock.setTimeout(() => {
|
|
2802
2995
|
this.unsafeRunAsync(eff, cb);
|
|
2803
2996
|
}, ms);
|
|
2804
|
-
return () => clearTimeout(handle);
|
|
2997
|
+
return () => clock.clearTimeout(handle);
|
|
2805
2998
|
});
|
|
2806
2999
|
}
|
|
2807
3000
|
// util para crear runtime default
|
|
@@ -2816,6 +3009,243 @@ var Runtime = class _Runtime {
|
|
|
2816
3009
|
this.emit({ type: "log", level, message, fields });
|
|
2817
3010
|
}
|
|
2818
3011
|
};
|
|
3012
|
+
var NATIVE_FAST_PATH_STEP_BUDGET = 32768;
|
|
3013
|
+
var NativeTopLevelRunner = (_class16 = class {
|
|
3014
|
+
constructor(runtime, effect, cb) {;_class16.prototype.__init99.call(this);_class16.prototype.__init100.call(this);_class16.prototype.__init101.call(this);_class16.prototype.__init102.call(this);
|
|
3015
|
+
this.runtime = runtime;
|
|
3016
|
+
this.current = effect;
|
|
3017
|
+
this.joiners.push(cb);
|
|
3018
|
+
this.frame = {
|
|
3019
|
+
id: 0,
|
|
3020
|
+
runtime,
|
|
3021
|
+
name: "native-fast-path",
|
|
3022
|
+
fiberContext: { trace: null },
|
|
3023
|
+
lane: runtime.lane,
|
|
3024
|
+
status: () => this.result ? "Done" : "Running",
|
|
3025
|
+
join: (joiner) => {
|
|
3026
|
+
if (this.result) joiner(this.result);
|
|
3027
|
+
else this.joiners.push(joiner);
|
|
3028
|
+
},
|
|
3029
|
+
interrupt: () => void 0,
|
|
3030
|
+
addFinalizer: (finalizer) => {
|
|
3031
|
+
this.finalizers.push(finalizer);
|
|
3032
|
+
}
|
|
3033
|
+
};
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
|
|
3037
|
+
__init99() {this.stack = []}
|
|
3038
|
+
__init100() {this.joiners = []}
|
|
3039
|
+
__init101() {this.finalizers = []}
|
|
3040
|
+
|
|
3041
|
+
__init102() {this.yielded = false}
|
|
3042
|
+
|
|
3043
|
+
start() {
|
|
3044
|
+
this.runLoop();
|
|
3045
|
+
}
|
|
3046
|
+
runLoop() {
|
|
3047
|
+
this.withFrame(() => {
|
|
3048
|
+
this.yielded = false;
|
|
3049
|
+
let budget = NATIVE_FAST_PATH_STEP_BUDGET;
|
|
3050
|
+
while (!this.result && budget-- > 0) {
|
|
3051
|
+
const current = this.current;
|
|
3052
|
+
switch (current._tag) {
|
|
3053
|
+
case "Succeed":
|
|
3054
|
+
this.onSuccess(current.value);
|
|
3055
|
+
break;
|
|
3056
|
+
case "Fail":
|
|
3057
|
+
this.onCause(_chunkMVGUEJ5Zcjs.Cause.fail(current.error));
|
|
3058
|
+
break;
|
|
3059
|
+
case "Sync":
|
|
3060
|
+
try {
|
|
3061
|
+
this.onSuccess(current.thunk(this.runtime.env));
|
|
3062
|
+
} catch (error) {
|
|
3063
|
+
this.onCause(_chunkMVGUEJ5Zcjs.Cause.fail(error));
|
|
3064
|
+
}
|
|
3065
|
+
break;
|
|
3066
|
+
case "FlatMap":
|
|
3067
|
+
this.stack.push({ _tag: "SuccessCont", k: current.andThen });
|
|
3068
|
+
this.current = current.first;
|
|
3069
|
+
break;
|
|
3070
|
+
case "Fold":
|
|
3071
|
+
this.stack.push({
|
|
3072
|
+
_tag: "FoldCont",
|
|
3073
|
+
onFailure: current.onFailure,
|
|
3074
|
+
onSuccess: current.onSuccess
|
|
3075
|
+
});
|
|
3076
|
+
this.current = current.first;
|
|
3077
|
+
break;
|
|
3078
|
+
case "Async":
|
|
3079
|
+
if (this.runAsync(current)) break;
|
|
3080
|
+
return;
|
|
3081
|
+
case "Fork":
|
|
3082
|
+
this.onSuccess(this.runtime.fork(current.effect, current.scopeId));
|
|
3083
|
+
break;
|
|
3084
|
+
case "Interruptibility":
|
|
3085
|
+
this.stack.push({ _tag: "InterruptibilityCont" });
|
|
3086
|
+
this.current = current.effect;
|
|
3087
|
+
break;
|
|
3088
|
+
case "InterruptibilityMask":
|
|
3089
|
+
this.stack.push({ _tag: "InterruptibilityCont" });
|
|
3090
|
+
try {
|
|
3091
|
+
this.current = current.body((effect) => ({
|
|
3092
|
+
_tag: "InterruptibilityRestore",
|
|
3093
|
+
depth: 0,
|
|
3094
|
+
effect
|
|
3095
|
+
}));
|
|
3096
|
+
} catch (error) {
|
|
3097
|
+
this.onCause(_chunkMVGUEJ5Zcjs.Cause.die(error));
|
|
3098
|
+
}
|
|
3099
|
+
break;
|
|
3100
|
+
case "InterruptibilityRestore":
|
|
3101
|
+
this.stack.push({ _tag: "InterruptibilityCont" });
|
|
3102
|
+
this.current = current.effect;
|
|
3103
|
+
break;
|
|
3104
|
+
case "FiberRefLocally": {
|
|
3105
|
+
const refs = this.fiberRefs();
|
|
3106
|
+
const hadValue = refs.has(current.refId);
|
|
3107
|
+
const previousValue = refs.get(current.refId);
|
|
3108
|
+
refs.set(current.refId, current.value);
|
|
3109
|
+
this.stack.push({
|
|
3110
|
+
_tag: "FiberRefCont",
|
|
3111
|
+
refId: current.refId,
|
|
3112
|
+
hadValue,
|
|
3113
|
+
previousValue
|
|
3114
|
+
});
|
|
3115
|
+
this.current = current.effect;
|
|
3116
|
+
break;
|
|
3117
|
+
}
|
|
3118
|
+
default:
|
|
3119
|
+
this.onCause(_chunkMVGUEJ5Zcjs.Cause.fail(new Error(`Unknown opcode: ${current._tag}`)));
|
|
3120
|
+
break;
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
if (!this.result && !this.yielded) {
|
|
3124
|
+
this.yielded = true;
|
|
3125
|
+
queueMicrotask(() => this.runLoop());
|
|
3126
|
+
}
|
|
3127
|
+
});
|
|
3128
|
+
}
|
|
3129
|
+
runAsync(current) {
|
|
3130
|
+
let registered = false;
|
|
3131
|
+
let settled = false;
|
|
3132
|
+
let syncExit;
|
|
3133
|
+
const resume = (exit) => {
|
|
3134
|
+
if (settled) return;
|
|
3135
|
+
settled = true;
|
|
3136
|
+
if (!registered) {
|
|
3137
|
+
syncExit = exit;
|
|
3138
|
+
return;
|
|
3139
|
+
}
|
|
3140
|
+
queueMicrotask(() => this.resumeAsync(exit));
|
|
3141
|
+
};
|
|
3142
|
+
try {
|
|
3143
|
+
current.register(this.runtime.env, resume);
|
|
3144
|
+
} catch (error) {
|
|
3145
|
+
this.onCause(_chunkMVGUEJ5Zcjs.Cause.die(error));
|
|
3146
|
+
return true;
|
|
3147
|
+
}
|
|
3148
|
+
registered = true;
|
|
3149
|
+
if (syncExit) {
|
|
3150
|
+
this.consumeExit(syncExit);
|
|
3151
|
+
return true;
|
|
3152
|
+
}
|
|
3153
|
+
return false;
|
|
3154
|
+
}
|
|
3155
|
+
resumeAsync(exit) {
|
|
3156
|
+
if (this.result) return;
|
|
3157
|
+
this.withFrame(() => this.consumeExit(exit));
|
|
3158
|
+
if (!this.result) this.runLoop();
|
|
3159
|
+
}
|
|
3160
|
+
consumeExit(exit) {
|
|
3161
|
+
if (exit._tag === "Success") this.onSuccess(exit.value);
|
|
3162
|
+
else this.onCause(exit.cause);
|
|
3163
|
+
}
|
|
3164
|
+
onSuccess(value) {
|
|
3165
|
+
let currentValue = value;
|
|
3166
|
+
while (true) {
|
|
3167
|
+
const frame = this.stack.pop();
|
|
3168
|
+
if (!frame) {
|
|
3169
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.succeed(currentValue));
|
|
3170
|
+
return;
|
|
3171
|
+
}
|
|
3172
|
+
if (frame._tag === "InterruptibilityCont") continue;
|
|
3173
|
+
if (frame._tag === "FiberRefCont") {
|
|
3174
|
+
this.restoreFiberRef(frame);
|
|
3175
|
+
continue;
|
|
3176
|
+
}
|
|
3177
|
+
if (frame._tag === "SuccessCont") {
|
|
3178
|
+
try {
|
|
3179
|
+
this.current = frame.k(currentValue);
|
|
3180
|
+
} catch (error) {
|
|
3181
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.die(error)));
|
|
3182
|
+
}
|
|
3183
|
+
return;
|
|
3184
|
+
}
|
|
3185
|
+
try {
|
|
3186
|
+
this.current = frame.onSuccess(currentValue);
|
|
3187
|
+
} catch (error) {
|
|
3188
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.die(error)));
|
|
3189
|
+
}
|
|
3190
|
+
return;
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
onCause(cause) {
|
|
3194
|
+
let currentCause = cause;
|
|
3195
|
+
while (this.stack.length > 0) {
|
|
3196
|
+
const frame = this.stack.pop();
|
|
3197
|
+
if (frame._tag === "InterruptibilityCont") continue;
|
|
3198
|
+
if (frame._tag === "FiberRefCont") {
|
|
3199
|
+
this.restoreFiberRef(frame);
|
|
3200
|
+
continue;
|
|
3201
|
+
}
|
|
3202
|
+
if (frame._tag === "FoldCont") {
|
|
3203
|
+
if (!_chunkMVGUEJ5Zcjs.Cause.isFailureOnly(currentCause)) continue;
|
|
3204
|
+
const failure = _chunkMVGUEJ5Zcjs.Cause.firstFailure(currentCause);
|
|
3205
|
+
if (failure._tag === "None") break;
|
|
3206
|
+
try {
|
|
3207
|
+
this.current = frame.onFailure(failure.value);
|
|
3208
|
+
return;
|
|
3209
|
+
} catch (error) {
|
|
3210
|
+
currentCause = _chunkMVGUEJ5Zcjs.Cause.fail(error);
|
|
3211
|
+
continue;
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(currentCause));
|
|
3216
|
+
}
|
|
3217
|
+
notify(exit) {
|
|
3218
|
+
if (this.result) return;
|
|
3219
|
+
this.result = exit;
|
|
3220
|
+
this.runFinalizers(exit);
|
|
3221
|
+
for (const joiner of this.joiners) joiner(exit);
|
|
3222
|
+
this.joiners.length = 0;
|
|
3223
|
+
}
|
|
3224
|
+
runFinalizers(exit) {
|
|
3225
|
+
while (this.finalizers.length > 0) {
|
|
3226
|
+
const finalizer = this.finalizers.pop();
|
|
3227
|
+
try {
|
|
3228
|
+
const result = finalizer(exit);
|
|
3229
|
+
if (result && typeof result === "object" && "_tag" in result) {
|
|
3230
|
+
this.runtime.unsafeRunAsync(result, () => void 0);
|
|
3231
|
+
}
|
|
3232
|
+
} catch (e9) {
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
fiberRefs() {
|
|
3237
|
+
this.frame.fiberContext.fiberRefs ??= /* @__PURE__ */ new Map();
|
|
3238
|
+
return this.frame.fiberContext.fiberRefs;
|
|
3239
|
+
}
|
|
3240
|
+
restoreFiberRef(frame) {
|
|
3241
|
+
const refs = this.fiberRefs();
|
|
3242
|
+
if (frame.hadValue) refs.set(frame.refId, frame.previousValue);
|
|
3243
|
+
else refs.delete(frame.refId);
|
|
3244
|
+
}
|
|
3245
|
+
withFrame(body) {
|
|
3246
|
+
return withCurrentFiber(this.frame, body);
|
|
3247
|
+
}
|
|
3248
|
+
}, _class16);
|
|
2819
3249
|
function fork(effect, env) {
|
|
2820
3250
|
return Runtime.make(_nullishCoalesce(env, () => ( {}))).fork(effect);
|
|
2821
3251
|
}
|
|
@@ -2909,7 +3339,7 @@ function resetAbortablePromiseStats() {
|
|
|
2909
3339
|
abortablePromiseLabels.clear();
|
|
2910
3340
|
}
|
|
2911
3341
|
var normalizeAbortablePromiseLabel = (label) => {
|
|
2912
|
-
const value = _optionalChain([label, 'optionalAccess',
|
|
3342
|
+
const value = _optionalChain([label, 'optionalAccess', _187 => _187.trim, 'call', _188 => _188()]);
|
|
2913
3343
|
return value && value.length > 0 ? value.slice(0, 160) : "anonymous";
|
|
2914
3344
|
};
|
|
2915
3345
|
var makeTimeoutReason = (timeoutMs, label) => ({
|
|
@@ -2938,7 +3368,7 @@ function fromPromiseAbortable(make, onReject, options = {}) {
|
|
|
2938
3368
|
done = true;
|
|
2939
3369
|
cleanup();
|
|
2940
3370
|
recordAbortablePromiseFinish(label, outcome);
|
|
2941
|
-
_optionalChain([options, 'access',
|
|
3371
|
+
_optionalChain([options, 'access', _189 => _189.onFinish, 'optionalCall', _190 => _190({
|
|
2942
3372
|
label,
|
|
2943
3373
|
outcome,
|
|
2944
3374
|
durationMs: Math.round(performance.now() - startedAt),
|
|
@@ -2947,23 +3377,23 @@ function fromPromiseAbortable(make, onReject, options = {}) {
|
|
|
2947
3377
|
cb(exit);
|
|
2948
3378
|
};
|
|
2949
3379
|
recordAbortablePromiseStart(label);
|
|
2950
|
-
_optionalChain([options, 'access',
|
|
3380
|
+
_optionalChain([options, 'access', _191 => _191.onStart, 'optionalCall', _192 => _192(label)]);
|
|
2951
3381
|
if (timeoutMs !== void 0 && timeoutMs > 0) {
|
|
2952
3382
|
timeoutHandle = setTimeout(() => {
|
|
2953
|
-
const reason = _nullishCoalesce(_optionalChain([options, 'access',
|
|
3383
|
+
const reason = _nullishCoalesce(_optionalChain([options, 'access', _193 => _193.timeoutReason, 'optionalCall', _194 => _194()]), () => ( makeTimeoutReason(timeoutMs, label)));
|
|
2954
3384
|
try {
|
|
2955
3385
|
controller.abort(reason);
|
|
2956
|
-
} catch (
|
|
3386
|
+
} catch (e10) {
|
|
2957
3387
|
controller.abort();
|
|
2958
3388
|
}
|
|
2959
|
-
finish("timeout", Exit.failCause(Cause.fail(onReject(reason))), reason);
|
|
3389
|
+
finish("timeout", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(reason))), reason);
|
|
2960
3390
|
}, timeoutMs);
|
|
2961
3391
|
}
|
|
2962
3392
|
let promise;
|
|
2963
3393
|
try {
|
|
2964
3394
|
promise = make(controller.signal, env);
|
|
2965
3395
|
} catch (err) {
|
|
2966
|
-
finish("failure", Exit.failCause(Cause.fail(onReject(err))), err);
|
|
3396
|
+
finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
|
|
2967
3397
|
return () => void 0;
|
|
2968
3398
|
}
|
|
2969
3399
|
promise.then((value) => {
|
|
@@ -2971,21 +3401,21 @@ function fromPromiseAbortable(make, onReject, options = {}) {
|
|
|
2971
3401
|
recordAbortablePromiseLateSettlement(label);
|
|
2972
3402
|
return;
|
|
2973
3403
|
}
|
|
2974
|
-
finish("success", Exit.succeed(value));
|
|
3404
|
+
finish("success", _chunkMVGUEJ5Zcjs.Exit.succeed(value));
|
|
2975
3405
|
}).catch((err) => {
|
|
2976
3406
|
if (done) {
|
|
2977
3407
|
recordAbortablePromiseLateSettlement(label);
|
|
2978
3408
|
return;
|
|
2979
3409
|
}
|
|
2980
|
-
finish("failure", Exit.failCause(Cause.fail(onReject(err))), err);
|
|
3410
|
+
finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
|
|
2981
3411
|
});
|
|
2982
3412
|
return () => {
|
|
2983
3413
|
if (done) return;
|
|
2984
3414
|
try {
|
|
2985
3415
|
controller.abort();
|
|
2986
|
-
} catch (
|
|
3416
|
+
} catch (e11) {
|
|
2987
3417
|
}
|
|
2988
|
-
finish("interrupt", Exit.failCause(Cause.interrupt()));
|
|
3418
|
+
finish("interrupt", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt()));
|
|
2989
3419
|
};
|
|
2990
3420
|
}
|
|
2991
3421
|
};
|
|
@@ -3027,21 +3457,22 @@ function setBenchmarkBudget(budget) {
|
|
|
3027
3457
|
function getBenchmarkBudget() {
|
|
3028
3458
|
return __benchmarkBudget;
|
|
3029
3459
|
}
|
|
3030
|
-
var RuntimeFiber = (
|
|
3460
|
+
var RuntimeFiber = (_class17 = class {
|
|
3031
3461
|
|
|
3032
3462
|
// 👇 CLAVE: guardar el runtime en el fiber (para getCurrentRuntime())
|
|
3033
3463
|
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3464
|
+
__init103() {this.closing = null}
|
|
3465
|
+
__init104() {this.finishing = false}
|
|
3466
|
+
__init105() {this.runState = RUN.RUNNING}
|
|
3467
|
+
__init106() {this.interrupted = false}
|
|
3468
|
+
__init107() {this.result = null}
|
|
3469
|
+
__init108() {this.joiners = []}
|
|
3040
3470
|
// estado de evaluación
|
|
3041
3471
|
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3472
|
+
__init109() {this.stack = []}
|
|
3473
|
+
__init110() {this.fiberFinalizers = []}
|
|
3474
|
+
__init111() {this.finalizersDrained = false}
|
|
3475
|
+
__init112() {this.interruptibilityDepth = 0}
|
|
3045
3476
|
|
|
3046
3477
|
|
|
3047
3478
|
|
|
@@ -3055,12 +3486,12 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3055
3486
|
|
|
3056
3487
|
// Reusable async callback state — avoids allocating a closure per Async step.
|
|
3057
3488
|
// These fields are reset at the start of each Async case and reused.
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3489
|
+
__init113() {this._syncResolved = false}
|
|
3490
|
+
__init114() {this._syncExit = null}
|
|
3491
|
+
__init115() {this._asyncRegistered = false}
|
|
3061
3492
|
|
|
3062
3493
|
|
|
3063
|
-
constructor(runtime, effect) {;
|
|
3494
|
+
constructor(runtime, effect) {;_class17.prototype.__init103.call(this);_class17.prototype.__init104.call(this);_class17.prototype.__init105.call(this);_class17.prototype.__init106.call(this);_class17.prototype.__init107.call(this);_class17.prototype.__init108.call(this);_class17.prototype.__init109.call(this);_class17.prototype.__init110.call(this);_class17.prototype.__init111.call(this);_class17.prototype.__init112.call(this);_class17.prototype.__init113.call(this);_class17.prototype.__init114.call(this);_class17.prototype.__init115.call(this);_class17.prototype.__init116.call(this);
|
|
3064
3495
|
this.id = nextId++;
|
|
3065
3496
|
this.runtime = runtime;
|
|
3066
3497
|
this.current = effect;
|
|
@@ -3073,21 +3504,15 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3073
3504
|
return;
|
|
3074
3505
|
}
|
|
3075
3506
|
this._syncResolved = true;
|
|
3076
|
-
_optionalChain([this, 'access',
|
|
3507
|
+
_optionalChain([this, 'access', _195 => _195._asyncDetach, 'optionalCall', _196 => _196()]);
|
|
3077
3508
|
this._asyncDetach = void 0;
|
|
3078
3509
|
if (exit._tag === "Success") {
|
|
3079
|
-
this.current = Async.succeed(exit.value);
|
|
3510
|
+
this.current = _chunkMVGUEJ5Zcjs.Async.succeed(exit.value);
|
|
3080
3511
|
this.schedule("async-resume");
|
|
3081
3512
|
return;
|
|
3082
3513
|
}
|
|
3083
|
-
|
|
3084
|
-
if (cause._tag === "Interrupt") {
|
|
3085
|
-
this.notify(Exit.failCause(Cause.interrupt()));
|
|
3086
|
-
} else if (cause._tag === "Fail") {
|
|
3087
|
-
this.current = Async.fail(cause.error);
|
|
3514
|
+
if (this.onCause(exit.cause)) {
|
|
3088
3515
|
this.schedule("async-resume");
|
|
3089
|
-
} else {
|
|
3090
|
-
this.notify(Exit.failCause(Cause.die(cause.defect)));
|
|
3091
3516
|
}
|
|
3092
3517
|
};
|
|
3093
3518
|
this.boundStep = () => {
|
|
@@ -3121,8 +3546,12 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3121
3546
|
this.runtime.hooks.emit(ev, {
|
|
3122
3547
|
fiberId: this.id,
|
|
3123
3548
|
scopeId: this.scopeId,
|
|
3124
|
-
traceId: _optionalChain([this, 'access',
|
|
3125
|
-
spanId: _optionalChain([this, 'access',
|
|
3549
|
+
traceId: _optionalChain([this, 'access', _197 => _197.fiberContext, 'optionalAccess', _198 => _198.trace, 'optionalAccess', _199 => _199.traceId]),
|
|
3550
|
+
spanId: _optionalChain([this, 'access', _200 => _200.fiberContext, 'optionalAccess', _201 => _201.trace, 'optionalAccess', _202 => _202.spanId]),
|
|
3551
|
+
parentSpanId: _optionalChain([this, 'access', _203 => _203.fiberContext, 'optionalAccess', _204 => _204.trace, 'optionalAccess', _205 => _205.parentSpanId]),
|
|
3552
|
+
traceState: _optionalChain([this, 'access', _206 => _206.fiberContext, 'optionalAccess', _207 => _207.trace, 'optionalAccess', _208 => _208.traceState]),
|
|
3553
|
+
baggage: _optionalChain([this, 'access', _209 => _209.fiberContext, 'optionalAccess', _210 => _210.trace, 'optionalAccess', _211 => _211.baggage]),
|
|
3554
|
+
sampled: _optionalChain([this, 'access', _212 => _212.fiberContext, 'optionalAccess', _213 => _213.trace, 'optionalAccess', _214 => _214.sampled])
|
|
3126
3555
|
});
|
|
3127
3556
|
}
|
|
3128
3557
|
addFinalizer(f) {
|
|
@@ -3142,7 +3571,7 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3142
3571
|
}
|
|
3143
3572
|
status() {
|
|
3144
3573
|
if (this.result == null) return "Running";
|
|
3145
|
-
if (this.result._tag === "Failure" && this.result.cause
|
|
3574
|
+
if (this.result._tag === "Failure" && _chunkMVGUEJ5Zcjs.Cause.isInterruptedOnly(this.result.cause)) return "Interrupted";
|
|
3146
3575
|
return "Done";
|
|
3147
3576
|
}
|
|
3148
3577
|
join(cb) {
|
|
@@ -3153,7 +3582,9 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3153
3582
|
if (this.result != null) return;
|
|
3154
3583
|
if (this.interrupted) return;
|
|
3155
3584
|
this.interrupted = true;
|
|
3156
|
-
this.
|
|
3585
|
+
if (this.isInterruptible()) {
|
|
3586
|
+
this.schedule("interrupt-step");
|
|
3587
|
+
}
|
|
3157
3588
|
}
|
|
3158
3589
|
schedule(tag = "step") {
|
|
3159
3590
|
if (this.runState === RUN.DONE || this.runState === RUN.QUEUED) return;
|
|
@@ -3168,7 +3599,7 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3168
3599
|
);
|
|
3169
3600
|
if (result === "dropped") {
|
|
3170
3601
|
this.runState = RUN.DONE;
|
|
3171
|
-
this.notify(Exit.failCause(Cause.die(new Error(`Brass scheduler dropped ${label} because the lane queue is full`))));
|
|
3602
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.die(new Error(`Brass scheduler dropped ${label} because the lane queue is full`))));
|
|
3172
3603
|
}
|
|
3173
3604
|
}
|
|
3174
3605
|
runFinalizersOnce(exit) {
|
|
@@ -3185,7 +3616,7 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3185
3616
|
unsafeRunAsync(eff, this.env, () => {
|
|
3186
3617
|
});
|
|
3187
3618
|
}
|
|
3188
|
-
} catch (
|
|
3619
|
+
} catch (e12) {
|
|
3189
3620
|
}
|
|
3190
3621
|
}
|
|
3191
3622
|
}
|
|
@@ -3196,7 +3627,7 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3196
3627
|
this.closing = exit;
|
|
3197
3628
|
this.runFinalizersOnce(exit);
|
|
3198
3629
|
this.result = exit;
|
|
3199
|
-
const status = exit._tag === "Success" ? "success" : exit.cause
|
|
3630
|
+
const status = exit._tag === "Success" ? "success" : _chunkMVGUEJ5Zcjs.Cause.isInterruptedOnly(exit.cause) ? "interrupted" : "failure";
|
|
3200
3631
|
this.emit({
|
|
3201
3632
|
type: "fiber.end",
|
|
3202
3633
|
fiberId: this.id,
|
|
@@ -3206,46 +3637,109 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3206
3637
|
for (const j of this.joiners) j(exit);
|
|
3207
3638
|
this.joiners.length = 0;
|
|
3208
3639
|
}
|
|
3640
|
+
isInterruptible() {
|
|
3641
|
+
return this.interruptibilityDepth === 0;
|
|
3642
|
+
}
|
|
3643
|
+
shouldInterruptNow() {
|
|
3644
|
+
return this.interrupted && this.isInterruptible();
|
|
3645
|
+
}
|
|
3646
|
+
enterInterruptibility(mode) {
|
|
3647
|
+
const previousDepth = this.interruptibilityDepth;
|
|
3648
|
+
this.interruptibilityDepth = mode === "uninterruptible" ? previousDepth + 1 : 0;
|
|
3649
|
+
return previousDepth;
|
|
3650
|
+
}
|
|
3651
|
+
restoreInterruptibility(previousDepth) {
|
|
3652
|
+
this.interruptibilityDepth = Math.max(0, previousDepth);
|
|
3653
|
+
}
|
|
3654
|
+
fiberRefs() {
|
|
3655
|
+
const ctx = this.fiberContext;
|
|
3656
|
+
if (!ctx.fiberRefs) ctx.fiberRefs = /* @__PURE__ */ new Map();
|
|
3657
|
+
return ctx.fiberRefs;
|
|
3658
|
+
}
|
|
3659
|
+
restoreFiberRef(frame) {
|
|
3660
|
+
const refs = this.fiberRefs();
|
|
3661
|
+
if (frame.hadValue) refs.set(frame.refId, frame.previousValue);
|
|
3662
|
+
else refs.delete(frame.refId);
|
|
3663
|
+
}
|
|
3209
3664
|
onSuccess(value) {
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
this.
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3665
|
+
let currentValue = value;
|
|
3666
|
+
while (true) {
|
|
3667
|
+
const frame = this.stack.pop();
|
|
3668
|
+
if (!frame) {
|
|
3669
|
+
if (this.shouldInterruptNow()) {
|
|
3670
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt()));
|
|
3671
|
+
} else {
|
|
3672
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.succeed(currentValue));
|
|
3673
|
+
}
|
|
3674
|
+
return;
|
|
3675
|
+
}
|
|
3676
|
+
if (frame._tag === "InterruptibilityCont") {
|
|
3677
|
+
this.restoreInterruptibility(frame.previousDepth);
|
|
3678
|
+
if (this.shouldInterruptNow()) {
|
|
3679
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt()));
|
|
3680
|
+
return;
|
|
3681
|
+
}
|
|
3682
|
+
continue;
|
|
3683
|
+
}
|
|
3684
|
+
if (frame._tag === "FiberRefCont") {
|
|
3685
|
+
this.restoreFiberRef(frame);
|
|
3686
|
+
continue;
|
|
3687
|
+
}
|
|
3688
|
+
if (frame._tag === "SuccessCont") {
|
|
3689
|
+
try {
|
|
3690
|
+
this.current = frame.k(currentValue);
|
|
3691
|
+
} catch (e) {
|
|
3692
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.die(e)));
|
|
3693
|
+
}
|
|
3694
|
+
return;
|
|
3695
|
+
}
|
|
3216
3696
|
try {
|
|
3217
|
-
this.current = frame.
|
|
3697
|
+
this.current = frame.onSuccess(currentValue);
|
|
3218
3698
|
} catch (e) {
|
|
3219
|
-
this.notify(Exit.failCause(Cause.die(e)));
|
|
3699
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.die(e)));
|
|
3220
3700
|
}
|
|
3221
3701
|
return;
|
|
3222
3702
|
}
|
|
3223
|
-
try {
|
|
3224
|
-
this.current = frame.onSuccess(value);
|
|
3225
|
-
} catch (e) {
|
|
3226
|
-
this.notify(Exit.failCause(Cause.die(e)));
|
|
3227
|
-
}
|
|
3228
3703
|
}
|
|
3229
3704
|
onFailure(error) {
|
|
3705
|
+
this.onCause(_chunkMVGUEJ5Zcjs.Cause.fail(error));
|
|
3706
|
+
}
|
|
3707
|
+
onCause(cause) {
|
|
3708
|
+
let currentCause = cause;
|
|
3230
3709
|
while (this.stack.length > 0) {
|
|
3231
3710
|
const fr = this.stack.pop();
|
|
3711
|
+
if (fr._tag === "InterruptibilityCont") {
|
|
3712
|
+
this.restoreInterruptibility(fr.previousDepth);
|
|
3713
|
+
if (this.shouldInterruptNow() && !_chunkMVGUEJ5Zcjs.Cause.isInterruptedOnly(currentCause)) {
|
|
3714
|
+
currentCause = _chunkMVGUEJ5Zcjs.Cause.then(currentCause, _chunkMVGUEJ5Zcjs.Cause.interrupt());
|
|
3715
|
+
}
|
|
3716
|
+
continue;
|
|
3717
|
+
}
|
|
3718
|
+
if (fr._tag === "FiberRefCont") {
|
|
3719
|
+
this.restoreFiberRef(fr);
|
|
3720
|
+
continue;
|
|
3721
|
+
}
|
|
3232
3722
|
if (fr._tag === "FoldCont") {
|
|
3723
|
+
if (!_chunkMVGUEJ5Zcjs.Cause.isFailureOnly(currentCause)) continue;
|
|
3724
|
+
const failure = _chunkMVGUEJ5Zcjs.Cause.firstFailure(currentCause);
|
|
3725
|
+
if (failure._tag === "None") break;
|
|
3233
3726
|
try {
|
|
3234
|
-
this.current = fr.onFailure(
|
|
3235
|
-
return;
|
|
3727
|
+
this.current = fr.onFailure(failure.value);
|
|
3728
|
+
return true;
|
|
3236
3729
|
} catch (e) {
|
|
3237
|
-
|
|
3730
|
+
currentCause = _chunkMVGUEJ5Zcjs.Cause.fail(e);
|
|
3238
3731
|
continue;
|
|
3239
3732
|
}
|
|
3240
3733
|
}
|
|
3241
3734
|
}
|
|
3242
|
-
this.notify(Exit.failCause(
|
|
3735
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(currentCause));
|
|
3736
|
+
return false;
|
|
3243
3737
|
}
|
|
3244
|
-
|
|
3738
|
+
__init116() {this.budget = DEFAULT_BUDGET2}
|
|
3245
3739
|
step() {
|
|
3246
3740
|
if (this.result != null) return STEP.DONE;
|
|
3247
|
-
if (this.
|
|
3248
|
-
this.
|
|
3741
|
+
if (this.shouldInterruptNow()) {
|
|
3742
|
+
this.onCause(_chunkMVGUEJ5Zcjs.Cause.interrupt());
|
|
3249
3743
|
return STEP.DONE;
|
|
3250
3744
|
}
|
|
3251
3745
|
this.budget = _nullishCoalesce(__benchmarkBudget, () => ( DEFAULT_BUDGET2));
|
|
@@ -3300,14 +3794,7 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3300
3794
|
if (resolvedExit._tag === "Success") {
|
|
3301
3795
|
this.onSuccess(resolvedExit.value);
|
|
3302
3796
|
} else {
|
|
3303
|
-
|
|
3304
|
-
if (cause._tag === "Interrupt") {
|
|
3305
|
-
this.notify(Exit.failCause(Cause.interrupt()));
|
|
3306
|
-
} else if (cause._tag === "Fail") {
|
|
3307
|
-
this.onFailure(cause.error);
|
|
3308
|
-
} else {
|
|
3309
|
-
this.notify(Exit.failCause(Cause.die(cause.defect)));
|
|
3310
|
-
}
|
|
3797
|
+
this.onCause(resolvedExit.cause);
|
|
3311
3798
|
}
|
|
3312
3799
|
break;
|
|
3313
3800
|
}
|
|
@@ -3318,7 +3805,7 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3318
3805
|
this._asyncDetach = void 0;
|
|
3319
3806
|
try {
|
|
3320
3807
|
canceler();
|
|
3321
|
-
} catch (
|
|
3808
|
+
} catch (e13) {
|
|
3322
3809
|
}
|
|
3323
3810
|
});
|
|
3324
3811
|
}
|
|
@@ -3329,6 +3816,47 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3329
3816
|
this.onSuccess(child);
|
|
3330
3817
|
break;
|
|
3331
3818
|
}
|
|
3819
|
+
case "Interruptibility": {
|
|
3820
|
+
const previousDepth = this.enterInterruptibility(current.mode);
|
|
3821
|
+
this.stack.push({ _tag: "InterruptibilityCont", previousDepth });
|
|
3822
|
+
this.current = current.effect;
|
|
3823
|
+
break;
|
|
3824
|
+
}
|
|
3825
|
+
case "InterruptibilityMask": {
|
|
3826
|
+
const previousDepth = this.enterInterruptibility("uninterruptible");
|
|
3827
|
+
this.stack.push({ _tag: "InterruptibilityCont", previousDepth });
|
|
3828
|
+
try {
|
|
3829
|
+
this.current = current.body((effect) => ({
|
|
3830
|
+
_tag: "InterruptibilityRestore",
|
|
3831
|
+
depth: previousDepth,
|
|
3832
|
+
effect
|
|
3833
|
+
}));
|
|
3834
|
+
} catch (e) {
|
|
3835
|
+
this.onCause(_chunkMVGUEJ5Zcjs.Cause.die(e));
|
|
3836
|
+
}
|
|
3837
|
+
break;
|
|
3838
|
+
}
|
|
3839
|
+
case "InterruptibilityRestore": {
|
|
3840
|
+
const previousDepth = this.interruptibilityDepth;
|
|
3841
|
+
this.restoreInterruptibility(current.depth);
|
|
3842
|
+
this.stack.push({ _tag: "InterruptibilityCont", previousDepth });
|
|
3843
|
+
this.current = current.effect;
|
|
3844
|
+
break;
|
|
3845
|
+
}
|
|
3846
|
+
case "FiberRefLocally": {
|
|
3847
|
+
const refs = this.fiberRefs();
|
|
3848
|
+
const hadValue = refs.has(current.refId);
|
|
3849
|
+
const previousValue = refs.get(current.refId);
|
|
3850
|
+
refs.set(current.refId, current.value);
|
|
3851
|
+
this.stack.push({
|
|
3852
|
+
_tag: "FiberRefCont",
|
|
3853
|
+
refId: current.refId,
|
|
3854
|
+
hadValue,
|
|
3855
|
+
previousValue
|
|
3856
|
+
});
|
|
3857
|
+
this.current = current.effect;
|
|
3858
|
+
break;
|
|
3859
|
+
}
|
|
3332
3860
|
case "Sync": {
|
|
3333
3861
|
try {
|
|
3334
3862
|
const a = current.thunk(this.env);
|
|
@@ -3362,7 +3890,7 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3362
3890
|
syncTrampoline() {
|
|
3363
3891
|
while (this.budget-- > 0) {
|
|
3364
3892
|
let cur = this.current;
|
|
3365
|
-
while (cur._tag === "FlatMap" && _optionalChain([cur, 'access',
|
|
3893
|
+
while (cur._tag === "FlatMap" && _optionalChain([cur, 'access', _215 => _215.first, 'optionalAccess', _216 => _216._tag]) === "FlatMap") {
|
|
3366
3894
|
this.stack.push({ _tag: "SuccessCont", k: cur.andThen });
|
|
3367
3895
|
cur = cur.first;
|
|
3368
3896
|
}
|
|
@@ -3377,7 +3905,7 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3377
3905
|
try {
|
|
3378
3906
|
this.current = andThen(first.value);
|
|
3379
3907
|
} catch (e) {
|
|
3380
|
-
this.notify(Exit.failCause(Cause.die(e)));
|
|
3908
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.die(e)));
|
|
3381
3909
|
return TRAMPOLINE.DONE;
|
|
3382
3910
|
}
|
|
3383
3911
|
continue;
|
|
@@ -3387,7 +3915,7 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3387
3915
|
const value = first.thunk(this.env);
|
|
3388
3916
|
this.current = andThen(value);
|
|
3389
3917
|
} catch (e) {
|
|
3390
|
-
this.notify(Exit.failCause(Cause.die(e)));
|
|
3918
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.die(e)));
|
|
3391
3919
|
return TRAMPOLINE.DONE;
|
|
3392
3920
|
}
|
|
3393
3921
|
continue;
|
|
@@ -3414,20 +3942,13 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3414
3942
|
try {
|
|
3415
3943
|
this.current = andThen(exit.value);
|
|
3416
3944
|
} catch (e) {
|
|
3417
|
-
this.notify(Exit.failCause(Cause.die(e)));
|
|
3945
|
+
this.notify(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.die(e)));
|
|
3418
3946
|
return TRAMPOLINE.DONE;
|
|
3419
3947
|
}
|
|
3420
3948
|
continue;
|
|
3421
3949
|
} else {
|
|
3422
3950
|
this.stack.push({ _tag: "SuccessCont", k: andThen });
|
|
3423
|
-
|
|
3424
|
-
if (cause._tag === "Fail") {
|
|
3425
|
-
this.onFailure(cause.error);
|
|
3426
|
-
} else if (cause._tag === "Interrupt") {
|
|
3427
|
-
this.notify(Exit.failCause(Cause.interrupt()));
|
|
3428
|
-
} else {
|
|
3429
|
-
this.notify(Exit.failCause(Cause.die(cause.defect)));
|
|
3430
|
-
}
|
|
3951
|
+
this.onCause(exit.cause);
|
|
3431
3952
|
return this.result != null ? TRAMPOLINE.DONE : TRAMPOLINE.CONTINUE;
|
|
3432
3953
|
}
|
|
3433
3954
|
}
|
|
@@ -3439,7 +3960,7 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3439
3960
|
this._asyncDetach = void 0;
|
|
3440
3961
|
try {
|
|
3441
3962
|
canceler();
|
|
3442
|
-
} catch (
|
|
3963
|
+
} catch (e14) {
|
|
3443
3964
|
}
|
|
3444
3965
|
});
|
|
3445
3966
|
}
|
|
@@ -3464,13 +3985,13 @@ var RuntimeFiber = (_class15 = class {
|
|
|
3464
3985
|
}
|
|
3465
3986
|
return TRAMPOLINE.CONTINUE;
|
|
3466
3987
|
}
|
|
3467
|
-
},
|
|
3988
|
+
}, _class17);
|
|
3468
3989
|
function getCurrentFiber() {
|
|
3469
3990
|
return _current;
|
|
3470
3991
|
}
|
|
3471
3992
|
function unsafeGetCurrentRuntime() {
|
|
3472
3993
|
const f = getCurrentFiber();
|
|
3473
|
-
if (!_optionalChain([f, 'optionalAccess',
|
|
3994
|
+
if (!_optionalChain([f, 'optionalAccess', _217 => _217.runtime])) {
|
|
3474
3995
|
throw new Error("unsafeGetCurrentRuntime: no current fiber/runtime");
|
|
3475
3996
|
}
|
|
3476
3997
|
return f.runtime;
|
|
@@ -3486,13 +4007,13 @@ function withCurrentFiber(fiber, f) {
|
|
|
3486
4007
|
}
|
|
3487
4008
|
|
|
3488
4009
|
// src/core/runtime/engine/JsFiberEngine.ts
|
|
3489
|
-
var JsFiberEngine = (
|
|
3490
|
-
constructor(runtime) {;
|
|
4010
|
+
var JsFiberEngine = (_class18 = class {
|
|
4011
|
+
constructor(runtime) {;_class18.prototype.__init117.call(this);_class18.prototype.__init118.call(this);
|
|
3491
4012
|
this.runtime = runtime;
|
|
3492
4013
|
}
|
|
3493
4014
|
|
|
3494
|
-
|
|
3495
|
-
|
|
4015
|
+
__init117() {this.kind = "ts"}
|
|
4016
|
+
__init118() {this.startedFibers = 0}
|
|
3496
4017
|
fork(effect, scopeId) {
|
|
3497
4018
|
this.startedFibers += 1;
|
|
3498
4019
|
const fiber = new RuntimeFiber(this.runtime, effect);
|
|
@@ -3512,212 +4033,7 @@ var JsFiberEngine = (_class16 = class {
|
|
|
3512
4033
|
pendingHostEffects: 0
|
|
3513
4034
|
};
|
|
3514
4035
|
}
|
|
3515
|
-
},
|
|
3516
|
-
|
|
3517
|
-
// src/core/runtime/scope.ts
|
|
3518
|
-
var nextScopeId = 1;
|
|
3519
|
-
function awaitAll(fibers) {
|
|
3520
|
-
return asyncEffect((_env, cb) => {
|
|
3521
|
-
let remaining = fibers.length;
|
|
3522
|
-
if (remaining === 0) {
|
|
3523
|
-
cb({ _tag: "Success", value: void 0 });
|
|
3524
|
-
return;
|
|
3525
|
-
}
|
|
3526
|
-
for (const f of fibers) {
|
|
3527
|
-
f.join(() => {
|
|
3528
|
-
remaining -= 1;
|
|
3529
|
-
if (remaining === 0) cb({ _tag: "Success", value: void 0 });
|
|
3530
|
-
});
|
|
3531
|
-
}
|
|
3532
|
-
});
|
|
3533
|
-
}
|
|
3534
|
-
var Scope = (_class17 = class _Scope {
|
|
3535
|
-
constructor(runtime, parentScopeId) {;_class17.prototype.__init104.call(this);_class17.prototype.__init105.call(this);_class17.prototype.__init106.call(this);_class17.prototype.__init107.call(this);
|
|
3536
|
-
this.runtime = runtime;
|
|
3537
|
-
this.parentScopeId = parentScopeId;
|
|
3538
|
-
this.id = nextScopeId++;
|
|
3539
|
-
const inferredParent = _nullishCoalesce(this.parentScopeId, () => ( _optionalChain([getCurrentFiber, 'call', _189 => _189(), 'optionalAccess', _190 => _190.scopeId])));
|
|
3540
|
-
if (this.runtime.hasActiveHooks()) {
|
|
3541
|
-
this.runtime.emit({
|
|
3542
|
-
type: "scope.open",
|
|
3543
|
-
scopeId: this.id,
|
|
3544
|
-
parentScopeId: inferredParent
|
|
3545
|
-
});
|
|
3546
|
-
}
|
|
3547
|
-
}
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
__init104() {this.closed = false}
|
|
3552
|
-
__init105() {this.children = /* @__PURE__ */ new Set()}
|
|
3553
|
-
__init106() {this.subScopes = /* @__PURE__ */ new Set()}
|
|
3554
|
-
__init107() {this.finalizers = []}
|
|
3555
|
-
/** registra un finalizer (LIFO) */
|
|
3556
|
-
addFinalizer(f) {
|
|
3557
|
-
if (this.closed) {
|
|
3558
|
-
throw new Error("Trying to add finalizer to closed scope");
|
|
3559
|
-
}
|
|
3560
|
-
this.finalizers.push(f);
|
|
3561
|
-
}
|
|
3562
|
-
/** crea un sub scope (mismo runtime) */
|
|
3563
|
-
subScope() {
|
|
3564
|
-
if (this.closed) throw new Error("Scope closed");
|
|
3565
|
-
const s = new _Scope(this.runtime, this.id);
|
|
3566
|
-
this.subScopes.add(s);
|
|
3567
|
-
return s;
|
|
3568
|
-
}
|
|
3569
|
-
/** ✅ fork en este scope */
|
|
3570
|
-
fork(eff) {
|
|
3571
|
-
if (this.closed) throw new Error("Scope closed");
|
|
3572
|
-
const f = this.runtime.fork(eff, this.id);
|
|
3573
|
-
this.children.add(f);
|
|
3574
|
-
f.join(() => this.children.delete(f));
|
|
3575
|
-
return f;
|
|
3576
|
-
}
|
|
3577
|
-
/** close fire-and-forget (no bloquea) */
|
|
3578
|
-
close(exit = { _tag: "Success", value: void 0 }) {
|
|
3579
|
-
this.runtime.fork(this.closeAsync(exit));
|
|
3580
|
-
}
|
|
3581
|
-
/** Emit the scope.close event if hooks are active. */
|
|
3582
|
-
emitCloseEvent(exit) {
|
|
3583
|
-
if (this.runtime.hasActiveHooks()) {
|
|
3584
|
-
const status = exit._tag === "Success" ? "success" : exit.cause._tag === "Interrupt" ? "interrupted" : "failure";
|
|
3585
|
-
this.runtime.emit({
|
|
3586
|
-
type: "scope.close",
|
|
3587
|
-
scopeId: this.id,
|
|
3588
|
-
status,
|
|
3589
|
-
error: exit._tag === "Failure" && exit.cause._tag === "Fail" ? exit.cause.error : void 0
|
|
3590
|
-
});
|
|
3591
|
-
}
|
|
3592
|
-
}
|
|
3593
|
-
/**
|
|
3594
|
-
* Build an effect that executes finalizers in LIFO order.
|
|
3595
|
-
*
|
|
3596
|
-
* Optimization over the original: instead of wrapping every finalizer in
|
|
3597
|
-
* `asyncFold(fin(exit), () => unit(), () => unit())` which creates 3 effect
|
|
3598
|
-
* nodes per finalizer (Fold + 2 Succeed), we use a single Sync thunk per
|
|
3599
|
-
* finalizer that catches errors inline. When the finalizer returns a
|
|
3600
|
-
* Succeed effect (like `unit()`), the Sync thunk completes without creating
|
|
3601
|
-
* additional effect nodes.
|
|
3602
|
-
*/
|
|
3603
|
-
buildFinalizerEffect(exit) {
|
|
3604
|
-
const fins = this.finalizers;
|
|
3605
|
-
if (fins.length === 0) return unit();
|
|
3606
|
-
let chain = unit();
|
|
3607
|
-
for (let i = fins.length - 1; i >= 0; i--) {
|
|
3608
|
-
const fin = fins[i];
|
|
3609
|
-
chain = asyncFlatMap(chain, () => {
|
|
3610
|
-
let result;
|
|
3611
|
-
try {
|
|
3612
|
-
result = fin(exit);
|
|
3613
|
-
} catch (e14) {
|
|
3614
|
-
return unit();
|
|
3615
|
-
}
|
|
3616
|
-
if (result._tag === "Succeed") {
|
|
3617
|
-
return unit();
|
|
3618
|
-
}
|
|
3619
|
-
return asyncFold(
|
|
3620
|
-
result,
|
|
3621
|
-
() => unit(),
|
|
3622
|
-
() => unit()
|
|
3623
|
-
);
|
|
3624
|
-
});
|
|
3625
|
-
}
|
|
3626
|
-
return chain;
|
|
3627
|
-
}
|
|
3628
|
-
closeAsync(exit = { _tag: "Success", value: void 0 }, opts = { awaitChildren: true }) {
|
|
3629
|
-
return asyncFlatMap(
|
|
3630
|
-
unit(),
|
|
3631
|
-
() => asyncEffect((env, cb) => {
|
|
3632
|
-
if (this.closed) {
|
|
3633
|
-
cb({ _tag: "Success", value: void 0 });
|
|
3634
|
-
return;
|
|
3635
|
-
}
|
|
3636
|
-
this.closed = true;
|
|
3637
|
-
const children = Array.from(this.children);
|
|
3638
|
-
const subScopes = Array.from(this.subScopes);
|
|
3639
|
-
for (const child of children) {
|
|
3640
|
-
child.interrupt();
|
|
3641
|
-
}
|
|
3642
|
-
const closeSubs = subScopes.reduceRight(
|
|
3643
|
-
(acc, s) => asyncFlatMap(acc, () => s.closeAsync(exit, opts)),
|
|
3644
|
-
unit()
|
|
3645
|
-
);
|
|
3646
|
-
const runFinalizers = this.buildFinalizerEffect(exit);
|
|
3647
|
-
const needsAwait = opts.awaitChildren && children.length > 0;
|
|
3648
|
-
const awaitChildrenEff = needsAwait ? awaitAll(children) : unit();
|
|
3649
|
-
const hasSubScopes = subScopes.length > 0;
|
|
3650
|
-
const hasNoFinalizers = this.finalizers.length === 0;
|
|
3651
|
-
if (!hasSubScopes && !needsAwait && hasNoFinalizers) {
|
|
3652
|
-
this.emitCloseEvent(exit);
|
|
3653
|
-
cb({ _tag: "Success", value: void 0 });
|
|
3654
|
-
return;
|
|
3655
|
-
}
|
|
3656
|
-
const all = asyncFlatMap(closeSubs, () => asyncFlatMap(awaitChildrenEff, () => runFinalizers));
|
|
3657
|
-
this.runtime.fork(all).join(() => {
|
|
3658
|
-
this.emitCloseEvent(exit);
|
|
3659
|
-
cb({ _tag: "Success", value: void 0 });
|
|
3660
|
-
});
|
|
3661
|
-
})
|
|
3662
|
-
);
|
|
3663
|
-
}
|
|
3664
|
-
}, _class17);
|
|
3665
|
-
function withScopeAsync(runtime, f) {
|
|
3666
|
-
return asyncEffect((_env, cb) => {
|
|
3667
|
-
const scope = new Scope(runtime);
|
|
3668
|
-
let done = false;
|
|
3669
|
-
const completeAfterClose = (exit) => {
|
|
3670
|
-
runtime.fork(scope.closeAsync(exit)).join(() => {
|
|
3671
|
-
if (done) return;
|
|
3672
|
-
done = true;
|
|
3673
|
-
cb(exit);
|
|
3674
|
-
});
|
|
3675
|
-
};
|
|
3676
|
-
const fiber = runtime.fork(f(scope));
|
|
3677
|
-
fiber.join(completeAfterClose);
|
|
3678
|
-
return () => {
|
|
3679
|
-
if (done) return;
|
|
3680
|
-
fiber.interrupt();
|
|
3681
|
-
runtime.fork(scope.closeAsync(Exit.failCause(Cause.interrupt())));
|
|
3682
|
-
};
|
|
3683
|
-
});
|
|
3684
|
-
}
|
|
3685
|
-
function withScope(runtime, f) {
|
|
3686
|
-
return withScopeAsync(runtime, (scope) => {
|
|
3687
|
-
const out = f(scope);
|
|
3688
|
-
if (out && typeof out === "object" && "_tag" in out) return out;
|
|
3689
|
-
return unit();
|
|
3690
|
-
});
|
|
3691
|
-
}
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
4036
|
+
}, _class18);
|
|
3721
4037
|
|
|
3722
4038
|
|
|
3723
4039
|
|
|
@@ -3770,4 +4086,4 @@ function withScope(runtime, f) {
|
|
|
3770
4086
|
|
|
3771
4087
|
|
|
3772
4088
|
|
|
3773
|
-
exports.
|
|
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;
|