brass-runtime 1.13.5 → 1.13.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/cli/main.cjs +2022 -0
- package/dist/agent/cli/main.js +184 -184
- package/dist/agent/index.cjs +153 -0
- package/dist/agent/index.js +153 -153
- package/dist/chunk-3IF374MG.js +121 -121
- package/dist/chunk-AC4RFFVX.cjs +407 -0
- package/dist/chunk-DB57UZBE.cjs +2879 -0
- package/dist/chunk-HRVX2IYW.js +345 -345
- package/dist/chunk-KT4IKCIU.cjs +2556 -0
- package/dist/chunk-TGOMLZ65.js +317 -317
- package/dist/http/index.cjs +453 -0
- package/dist/http/index.js +74 -74
- package/dist/index.cjs +855 -0
- package/dist/index.js +340 -340
- package/package.json +5 -5
- package/dist/agent/cli/main.d.mts +0 -1
- package/dist/agent/index.d.mts +0 -688
- package/dist/effect-ISvXPLgc.d.mts +0 -797
- package/dist/http/index.d.mts +0 -154
- package/dist/index.d.mts +0 -258
- package/dist/stream-C0-LWnUP.d.mts +0 -66
package/dist/chunk-TGOMLZ65.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/core/types/asyncEffect.ts
|
|
2
2
|
var Async = {
|
|
3
3
|
succeed: (value) => ({ _tag: "Succeed", value }),
|
|
4
4
|
fail: (error) => ({ _tag: "Fail", error }),
|
|
@@ -124,14 +124,14 @@ var PushStatus = /* @__PURE__ */ ((PushStatus3) => {
|
|
|
124
124
|
PushStatus3[PushStatus3["Dropped"] = 2] = "Dropped";
|
|
125
125
|
return PushStatus3;
|
|
126
126
|
})(PushStatus || {});
|
|
127
|
-
var RingBuffer =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
var RingBuffer = class {
|
|
128
|
+
buf;
|
|
129
|
+
head = 0;
|
|
130
|
+
tail = 0;
|
|
131
|
+
size_ = 0;
|
|
132
132
|
// nuevo
|
|
133
|
-
|
|
134
|
-
constructor(initialCapacity = 1024, maxCapacity = initialCapacity) {
|
|
133
|
+
maxCap;
|
|
134
|
+
constructor(initialCapacity = 1024, maxCapacity = initialCapacity) {
|
|
135
135
|
let initPow = Math.max(2, initialCapacity);
|
|
136
136
|
initPow--;
|
|
137
137
|
initPow |= initPow >>> 1;
|
|
@@ -200,10 +200,10 @@ var RingBuffer = (_class = class {
|
|
|
200
200
|
this.head = 0;
|
|
201
201
|
this.tail = this.size_;
|
|
202
202
|
}
|
|
203
|
-
}
|
|
203
|
+
};
|
|
204
204
|
|
|
205
205
|
// src/core/runtime/wasmModule.ts
|
|
206
|
-
|
|
206
|
+
import { createRequire } from "module";
|
|
207
207
|
var cachedWasmModule;
|
|
208
208
|
var cachedWasmModuleErrors = [];
|
|
209
209
|
function resolveWasmModule(options = {}) {
|
|
@@ -252,33 +252,33 @@ function remember(options, value, errors) {
|
|
|
252
252
|
return value;
|
|
253
253
|
}
|
|
254
254
|
function getBestRequire() {
|
|
255
|
-
return
|
|
255
|
+
return getNonWebpackRequire() ?? getRuntimeRequire() ?? getCreateRequire();
|
|
256
256
|
}
|
|
257
257
|
function getNonWebpackRequire() {
|
|
258
258
|
try {
|
|
259
259
|
return (0, eval)("typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : undefined");
|
|
260
|
-
} catch
|
|
260
|
+
} catch {
|
|
261
261
|
return void 0;
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
function getRuntimeRequire() {
|
|
265
265
|
try {
|
|
266
266
|
return (0, eval)("typeof require === 'function' ? require : undefined");
|
|
267
|
-
} catch
|
|
267
|
+
} catch {
|
|
268
268
|
return void 0;
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
function getCreateRequire() {
|
|
272
272
|
try {
|
|
273
|
-
return
|
|
274
|
-
} catch
|
|
273
|
+
return createRequire(import.meta.url);
|
|
274
|
+
} catch {
|
|
275
275
|
return void 0;
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
function getCwd() {
|
|
279
279
|
try {
|
|
280
280
|
return (0, eval)("typeof process !== 'undefined' ? process.cwd() : ''");
|
|
281
|
-
} catch
|
|
281
|
+
} catch {
|
|
282
282
|
return "";
|
|
283
283
|
}
|
|
284
284
|
}
|
|
@@ -291,18 +291,18 @@ var cachedWasmCtor;
|
|
|
291
291
|
function resolveWasmRingBuffer() {
|
|
292
292
|
if (cachedWasmCtor !== void 0) return cachedWasmCtor;
|
|
293
293
|
const mod = resolveWasmModule();
|
|
294
|
-
cachedWasmCtor =
|
|
294
|
+
cachedWasmCtor = mod?.BrassWasmRingBuffer ?? null;
|
|
295
295
|
return cachedWasmCtor;
|
|
296
296
|
}
|
|
297
|
-
var WasmRingBuffer =
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
constructor(initialCapacity, maxCapacity) {
|
|
297
|
+
var WasmRingBuffer = class {
|
|
298
|
+
engine = "wasm";
|
|
299
|
+
fallbackUsed = false;
|
|
300
|
+
inner;
|
|
301
|
+
pushes = 0;
|
|
302
|
+
shifts = 0;
|
|
303
|
+
clears = 0;
|
|
304
|
+
dropped = 0;
|
|
305
|
+
constructor(initialCapacity, maxCapacity) {
|
|
306
306
|
const Ctor = resolveWasmRingBuffer();
|
|
307
307
|
if (!Ctor) {
|
|
308
308
|
throw new Error("brass-runtime wasm ring buffer is not available. Run npm run build:wasm first.");
|
|
@@ -347,19 +347,19 @@ var WasmRingBuffer = (_class2 = class {
|
|
|
347
347
|
}
|
|
348
348
|
};
|
|
349
349
|
}
|
|
350
|
-
}
|
|
351
|
-
var JsBoundedRingBuffer =
|
|
352
|
-
constructor(inner, fallbackUsed) {
|
|
350
|
+
};
|
|
351
|
+
var JsBoundedRingBuffer = class {
|
|
352
|
+
constructor(inner, fallbackUsed) {
|
|
353
353
|
this.inner = inner;
|
|
354
354
|
this.fallbackUsed = fallbackUsed;
|
|
355
355
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
356
|
+
inner;
|
|
357
|
+
fallbackUsed;
|
|
358
|
+
engine = "js";
|
|
359
|
+
pushes = 0;
|
|
360
|
+
shifts = 0;
|
|
361
|
+
clears = 0;
|
|
362
|
+
dropped = 0;
|
|
363
363
|
get length() {
|
|
364
364
|
return this.inner.length;
|
|
365
365
|
}
|
|
@@ -398,9 +398,9 @@ var JsBoundedRingBuffer = (_class3 = class {
|
|
|
398
398
|
}
|
|
399
399
|
};
|
|
400
400
|
}
|
|
401
|
-
}
|
|
401
|
+
};
|
|
402
402
|
function makeBoundedRingBuffer(initialCapacity, maxCapacity = initialCapacity, options = {}) {
|
|
403
|
-
const engine =
|
|
403
|
+
const engine = options.engine ?? "auto";
|
|
404
404
|
if (engine === "js") {
|
|
405
405
|
return new JsBoundedRingBuffer(new RingBuffer(initialCapacity, maxCapacity), false);
|
|
406
406
|
}
|
|
@@ -428,7 +428,7 @@ var scheduleMacro = (() => {
|
|
|
428
428
|
ch.port1.onmessage = () => {
|
|
429
429
|
const f = cb;
|
|
430
430
|
cb = null;
|
|
431
|
-
|
|
431
|
+
f?.();
|
|
432
432
|
};
|
|
433
433
|
return (f) => {
|
|
434
434
|
cb = f;
|
|
@@ -439,39 +439,39 @@ var scheduleMacro = (() => {
|
|
|
439
439
|
})();
|
|
440
440
|
function resolveWasmScheduler() {
|
|
441
441
|
const mod = resolveWasmModule();
|
|
442
|
-
return
|
|
442
|
+
return mod?.BrassWasmSchedulerStateMachine ?? null;
|
|
443
443
|
}
|
|
444
|
-
var JsSchedulerState =
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
constructor(options) {
|
|
456
|
-
const initial =
|
|
457
|
-
const max =
|
|
444
|
+
var JsSchedulerState = class {
|
|
445
|
+
tasks;
|
|
446
|
+
tags;
|
|
447
|
+
flushing = false;
|
|
448
|
+
scheduled = false;
|
|
449
|
+
scheduledFlushes = 0;
|
|
450
|
+
completedFlushes = 0;
|
|
451
|
+
enqueuedTasks = 0;
|
|
452
|
+
executedTasks = 0;
|
|
453
|
+
droppedTasks = 0;
|
|
454
|
+
yieldedByBudget = 0;
|
|
455
|
+
constructor(options) {
|
|
456
|
+
const initial = options.initialCapacity ?? 1024;
|
|
457
|
+
const max = options.maxCapacity ?? initial;
|
|
458
458
|
this.tasks = makeBoundedRingBuffer(initial, max, { engine: options.engine });
|
|
459
459
|
this.tags = makeBoundedRingBuffer(initial, max, { engine: options.engine });
|
|
460
460
|
}
|
|
461
|
-
}
|
|
462
|
-
var WasmSchedulerState =
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
constructor(options) {
|
|
461
|
+
};
|
|
462
|
+
var WasmSchedulerState = class {
|
|
463
|
+
machine;
|
|
464
|
+
nextRef = 1;
|
|
465
|
+
tasks = /* @__PURE__ */ new Map();
|
|
466
|
+
tags = /* @__PURE__ */ new Map();
|
|
467
|
+
constructor(options) {
|
|
468
468
|
const Ctor = resolveWasmScheduler();
|
|
469
469
|
if (!Ctor) throw new Error("brass-runtime wasm scheduler is not available. Run npm run build:wasm first.");
|
|
470
470
|
this.machine = new Ctor(
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
471
|
+
options.initialCapacity ?? 1024,
|
|
472
|
+
options.maxCapacity ?? SCHEDULER_QUEUE_CAPACITY,
|
|
473
|
+
options.flushBudget ?? FLUSH_BUDGET,
|
|
474
|
+
options.microThreshold ?? MICRO_THRESHOLD
|
|
475
475
|
);
|
|
476
476
|
}
|
|
477
477
|
enqueue(task, tag) {
|
|
@@ -492,7 +492,7 @@ var WasmSchedulerState = (_class5 = class {
|
|
|
492
492
|
const ref = this.machine.shift();
|
|
493
493
|
if (ref === 0) return void 0;
|
|
494
494
|
const task = this.tasks.get(ref);
|
|
495
|
-
const tag =
|
|
495
|
+
const tag = this.tags.get(ref) ?? "anonymous";
|
|
496
496
|
this.tasks.delete(ref);
|
|
497
497
|
this.tags.delete(ref);
|
|
498
498
|
return task ? { task, tag } : void 0;
|
|
@@ -506,20 +506,20 @@ var WasmSchedulerState = (_class5 = class {
|
|
|
506
506
|
stats() {
|
|
507
507
|
return { engine: "wasm", fallbackUsed: false, data: JSON.parse(this.machine.stats_json()) };
|
|
508
508
|
}
|
|
509
|
-
}
|
|
510
|
-
var Scheduler =
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
509
|
+
};
|
|
510
|
+
var Scheduler = class {
|
|
511
|
+
engine;
|
|
512
|
+
js;
|
|
513
|
+
wasm;
|
|
514
|
+
flushBudget;
|
|
515
|
+
microThreshold;
|
|
516
|
+
fallbackUsed;
|
|
517
517
|
// Cached flush closure — avoids creating a new closure on every requestFlush
|
|
518
|
-
|
|
519
|
-
constructor(options = {}) {
|
|
520
|
-
this.flushBudget =
|
|
521
|
-
this.microThreshold =
|
|
522
|
-
const requested =
|
|
518
|
+
boundFlush = () => this.flush();
|
|
519
|
+
constructor(options = {}) {
|
|
520
|
+
this.flushBudget = options.flushBudget ?? FLUSH_BUDGET;
|
|
521
|
+
this.microThreshold = options.microThreshold ?? MICRO_THRESHOLD;
|
|
522
|
+
const requested = options.engine ?? "js";
|
|
523
523
|
if (requested === "wasm") {
|
|
524
524
|
this.wasm = new WasmSchedulerState(options);
|
|
525
525
|
this.engine = "wasm";
|
|
@@ -640,7 +640,7 @@ var Scheduler = (_class6 = class {
|
|
|
640
640
|
}
|
|
641
641
|
}
|
|
642
642
|
}
|
|
643
|
-
}
|
|
643
|
+
};
|
|
644
644
|
var globalScheduler = new Scheduler();
|
|
645
645
|
|
|
646
646
|
// src/core/runtime/contex.ts
|
|
@@ -651,25 +651,25 @@ function makeForkPolicy(env, hooks) {
|
|
|
651
651
|
const svc = resolveForkServices(env);
|
|
652
652
|
return {
|
|
653
653
|
initChild(fiber, parent, scopeId) {
|
|
654
|
-
const parentCtx =
|
|
655
|
-
const trace = forkTrace(svc,
|
|
654
|
+
const parentCtx = parent?.fiberContext;
|
|
655
|
+
const trace = forkTrace(svc, parentCtx?.trace ?? null);
|
|
656
656
|
fiber.fiberContext = {
|
|
657
|
-
log:
|
|
657
|
+
log: parentCtx?.log ?? emptyContext,
|
|
658
658
|
trace
|
|
659
659
|
};
|
|
660
|
-
fiber.parentFiberId =
|
|
661
|
-
fiber.name = svc.childName(
|
|
660
|
+
fiber.parentFiberId = parent?.id;
|
|
661
|
+
fiber.name = svc.childName(parent?.name);
|
|
662
662
|
if (scopeId !== void 0) fiber.scopeId = scopeId;
|
|
663
663
|
hooks.emit(
|
|
664
664
|
{
|
|
665
665
|
type: "fiber.start",
|
|
666
666
|
fiberId: fiber.id,
|
|
667
|
-
parentFiberId:
|
|
667
|
+
parentFiberId: parent?.id,
|
|
668
668
|
scopeId: fiber.scopeId,
|
|
669
669
|
// ✅ ahora viaja
|
|
670
670
|
name: fiber.name
|
|
671
671
|
},
|
|
672
|
-
{ fiberId:
|
|
672
|
+
{ fiberId: parent?.id, traceId: parentCtx?.trace?.traceId, spanId: parentCtx?.trace?.spanId }
|
|
673
673
|
);
|
|
674
674
|
}
|
|
675
675
|
};
|
|
@@ -679,15 +679,15 @@ function resolveForkServices(env) {
|
|
|
679
679
|
newTraceId: () => randomRuntimeId("trace"),
|
|
680
680
|
newSpanId: () => randomRuntimeId("span")
|
|
681
681
|
};
|
|
682
|
-
const brass =
|
|
683
|
-
const tracer =
|
|
684
|
-
const seed =
|
|
685
|
-
const childName =
|
|
682
|
+
const brass = env?.brass;
|
|
683
|
+
const tracer = brass?.tracer ?? defaultTracer;
|
|
684
|
+
const seed = brass?.traceSeed;
|
|
685
|
+
const childName = brass?.childName ?? ((p) => p ? `${p}/child` : void 0);
|
|
686
686
|
return { tracer, seed, childName };
|
|
687
687
|
}
|
|
688
688
|
function randomRuntimeId(prefix) {
|
|
689
689
|
const cryptoLike = globalThis.crypto;
|
|
690
|
-
if (typeof
|
|
690
|
+
if (typeof cryptoLike?.randomUUID === "function") {
|
|
691
691
|
return cryptoLike.randomUUID();
|
|
692
692
|
}
|
|
693
693
|
return `${prefix}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
@@ -717,13 +717,13 @@ var DefaultHostExecutor = {
|
|
|
717
717
|
};
|
|
718
718
|
|
|
719
719
|
// src/core/runtime/engine/JsFiberEngine.ts
|
|
720
|
-
var JsFiberEngine =
|
|
721
|
-
constructor(runtime) {
|
|
720
|
+
var JsFiberEngine = class {
|
|
721
|
+
constructor(runtime) {
|
|
722
722
|
this.runtime = runtime;
|
|
723
723
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
724
|
+
runtime;
|
|
725
|
+
kind = "js";
|
|
726
|
+
startedFibers = 0;
|
|
727
727
|
fork(effect, scopeId) {
|
|
728
728
|
this.startedFibers += 1;
|
|
729
729
|
const fiber = new RuntimeFiber(this.runtime, effect);
|
|
@@ -743,12 +743,12 @@ var JsFiberEngine = (_class7 = class {
|
|
|
743
743
|
pendingHostEffects: 0
|
|
744
744
|
};
|
|
745
745
|
}
|
|
746
|
-
}
|
|
746
|
+
};
|
|
747
747
|
|
|
748
748
|
// src/core/runtime/engine/opcodes.ts
|
|
749
|
-
var HostRegistry =
|
|
750
|
-
|
|
751
|
-
|
|
749
|
+
var HostRegistry = class {
|
|
750
|
+
nextRef = 1;
|
|
751
|
+
refs = /* @__PURE__ */ new Map();
|
|
752
752
|
register(value) {
|
|
753
753
|
const ref = this.nextRef++;
|
|
754
754
|
this.refs.set(ref, value);
|
|
@@ -772,10 +772,10 @@ var HostRegistry = (_class8 = class {constructor() { _class8.prototype.__init29.
|
|
|
772
772
|
size() {
|
|
773
773
|
return this.refs.size;
|
|
774
774
|
}
|
|
775
|
-
}
|
|
776
|
-
var ProgramBuilder =
|
|
777
|
-
|
|
778
|
-
|
|
775
|
+
};
|
|
776
|
+
var ProgramBuilder = class {
|
|
777
|
+
nodes = [];
|
|
778
|
+
registry = new HostRegistry();
|
|
779
779
|
compile(effect) {
|
|
780
780
|
const root = this.visit(effect);
|
|
781
781
|
return {
|
|
@@ -839,14 +839,14 @@ var ProgramBuilder = (_class9 = class {constructor() { _class9.prototype.__init3
|
|
|
839
839
|
return this.add(current.decode === void 0 ? base : { ...base, decodeRef: this.registry.register(current.decode) });
|
|
840
840
|
}
|
|
841
841
|
default:
|
|
842
|
-
return this.add({ tag: "Fail", errorRef: this.registry.register(new Error(`Unknown Async opcode: ${
|
|
842
|
+
return this.add({ tag: "Fail", errorRef: this.registry.register(new Error(`Unknown Async opcode: ${current?._tag}`)) });
|
|
843
843
|
}
|
|
844
844
|
}
|
|
845
|
-
}
|
|
845
|
+
};
|
|
846
846
|
|
|
847
847
|
// src/core/runtime/engine/FiberHandleImpl.ts
|
|
848
|
-
var EngineFiberHandle =
|
|
849
|
-
constructor(id, runtime, onScheduledStep, onInterrupt, onJoiner, onQueued) {
|
|
848
|
+
var EngineFiberHandle = class {
|
|
849
|
+
constructor(id, runtime, onScheduledStep, onInterrupt, onJoiner, onQueued) {
|
|
850
850
|
this.onScheduledStep = onScheduledStep;
|
|
851
851
|
this.onInterrupt = onInterrupt;
|
|
852
852
|
this.onJoiner = onJoiner;
|
|
@@ -854,22 +854,22 @@ var EngineFiberHandle = (_class10 = class {
|
|
|
854
854
|
this.id = id;
|
|
855
855
|
this.runtime = runtime;
|
|
856
856
|
}
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
857
|
+
onScheduledStep;
|
|
858
|
+
onInterrupt;
|
|
859
|
+
onJoiner;
|
|
860
|
+
onQueued;
|
|
861
|
+
id;
|
|
862
|
+
runtime;
|
|
863
|
+
fiberContext;
|
|
864
|
+
name;
|
|
865
|
+
scopeId;
|
|
866
|
+
parentFiberId;
|
|
867
|
+
result = null;
|
|
868
|
+
joiners = [];
|
|
869
|
+
finalizers = [];
|
|
870
|
+
finalizersDrained = false;
|
|
871
|
+
internalStatus = "running";
|
|
872
|
+
queued = false;
|
|
873
873
|
status() {
|
|
874
874
|
if (this.result == null) return "Running";
|
|
875
875
|
if (this.result._tag === "Failure" && this.result.cause._tag === "Interrupt") return "Interrupted";
|
|
@@ -884,7 +884,7 @@ var EngineFiberHandle = (_class10 = class {
|
|
|
884
884
|
join(cb) {
|
|
885
885
|
if (this.result != null) cb(this.result);
|
|
886
886
|
else {
|
|
887
|
-
|
|
887
|
+
this.onJoiner?.(this.id);
|
|
888
888
|
this.joiners.push(cb);
|
|
889
889
|
}
|
|
890
890
|
}
|
|
@@ -899,7 +899,7 @@ var EngineFiberHandle = (_class10 = class {
|
|
|
899
899
|
if (this.result != null || this.queued) return;
|
|
900
900
|
this.queued = true;
|
|
901
901
|
this.internalStatus = "queued";
|
|
902
|
-
|
|
902
|
+
this.onQueued?.(this.id);
|
|
903
903
|
this.runtime.scheduler.schedule(() => {
|
|
904
904
|
this.queued = false;
|
|
905
905
|
if (this.result != null) return;
|
|
@@ -910,8 +910,8 @@ var EngineFiberHandle = (_class10 = class {
|
|
|
910
910
|
this.runtime.hooks.emit(ev, {
|
|
911
911
|
fiberId: this.id,
|
|
912
912
|
scopeId: this.scopeId,
|
|
913
|
-
traceId:
|
|
914
|
-
spanId:
|
|
913
|
+
traceId: this.fiberContext?.trace?.traceId,
|
|
914
|
+
spanId: this.fiberContext?.trace?.spanId
|
|
915
915
|
});
|
|
916
916
|
}
|
|
917
917
|
succeed(value) {
|
|
@@ -951,21 +951,21 @@ var EngineFiberHandle = (_class10 = class {
|
|
|
951
951
|
if (eff && typeof eff === "object" && "_tag" in eff) {
|
|
952
952
|
this.runtime.fork(eff);
|
|
953
953
|
}
|
|
954
|
-
} catch
|
|
954
|
+
} catch {
|
|
955
955
|
}
|
|
956
956
|
}
|
|
957
957
|
}
|
|
958
|
-
}
|
|
958
|
+
};
|
|
959
959
|
|
|
960
960
|
// src/core/runtime/engine/bridge/ReferenceWasmBridge.ts
|
|
961
|
-
var ReferenceWasmBridge =
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
961
|
+
var ReferenceWasmBridge = class {
|
|
962
|
+
kind = "wasm-reference";
|
|
963
|
+
nextFiberId = 1;
|
|
964
|
+
fibers = /* @__PURE__ */ new Map();
|
|
965
|
+
started = 0;
|
|
966
|
+
completed = 0;
|
|
967
|
+
failed = 0;
|
|
968
|
+
interrupted = 0;
|
|
969
969
|
createFiber(program) {
|
|
970
970
|
const id = this.nextFiberId++;
|
|
971
971
|
this.started += 1;
|
|
@@ -1042,7 +1042,7 @@ var ReferenceWasmBridge = (_class11 = class {constructor() { _class11.prototype.
|
|
|
1042
1042
|
step(fiber) {
|
|
1043
1043
|
while (true) {
|
|
1044
1044
|
if (fiber.status === "interrupted") {
|
|
1045
|
-
const event =
|
|
1045
|
+
const event = fiber.lastEvent ?? { kind: "Interrupted", fiberId: fiber.id, reasonRef: 0 };
|
|
1046
1046
|
fiber.lastEvent = event;
|
|
1047
1047
|
return event;
|
|
1048
1048
|
}
|
|
@@ -1117,7 +1117,7 @@ var ReferenceWasmBridge = (_class11 = class {constructor() { _class11.prototype.
|
|
|
1117
1117
|
fiber.lastEvent = event;
|
|
1118
1118
|
return event;
|
|
1119
1119
|
}
|
|
1120
|
-
}
|
|
1120
|
+
};
|
|
1121
1121
|
function cloneProgram(program) {
|
|
1122
1122
|
return {
|
|
1123
1123
|
version: program.version,
|
|
@@ -1127,10 +1127,10 @@ function cloneProgram(program) {
|
|
|
1127
1127
|
}
|
|
1128
1128
|
|
|
1129
1129
|
// src/core/runtime/engine/bridge/WasmPackFiberBridge.ts
|
|
1130
|
-
var WasmPackFiberBridge =
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
constructor(modulePath) {
|
|
1130
|
+
var WasmPackFiberBridge = class {
|
|
1131
|
+
kind = "wasm";
|
|
1132
|
+
vm;
|
|
1133
|
+
constructor(modulePath) {
|
|
1134
1134
|
const mod = loadWasmModule(modulePath);
|
|
1135
1135
|
this.vm = new mod.BrassWasmVm();
|
|
1136
1136
|
}
|
|
@@ -1158,7 +1158,7 @@ var WasmPackFiberBridge = (_class12 = class {
|
|
|
1158
1158
|
stats() {
|
|
1159
1159
|
return JSON.parse(this.vm.stats_json());
|
|
1160
1160
|
}
|
|
1161
|
-
}
|
|
1161
|
+
};
|
|
1162
1162
|
function loadWasmModule(modulePath) {
|
|
1163
1163
|
const mod = resolveWasmModule({ modulePath });
|
|
1164
1164
|
if (mod) return mod;
|
|
@@ -1179,17 +1179,17 @@ var FIBER_STATE_DONE = 3;
|
|
|
1179
1179
|
var FIBER_STATE_FAILED = 4;
|
|
1180
1180
|
var FIBER_STATE_INTERRUPTED = 5;
|
|
1181
1181
|
var WasmFiberRegistryBridge = class {
|
|
1182
|
-
|
|
1182
|
+
registry;
|
|
1183
1183
|
constructor() {
|
|
1184
1184
|
const mod = resolveWasmModule();
|
|
1185
|
-
const Ctor =
|
|
1185
|
+
const Ctor = mod?.BrassWasmFiberRegistry;
|
|
1186
1186
|
if (!Ctor) {
|
|
1187
1187
|
throw new Error("brass-runtime wasm fiber registry is not available. Run npm run build:wasm first.");
|
|
1188
1188
|
}
|
|
1189
1189
|
this.registry = new Ctor();
|
|
1190
1190
|
}
|
|
1191
1191
|
registerFiber(fiberId, parentId, scopeId) {
|
|
1192
|
-
this.registry.register_fiber(fiberId,
|
|
1192
|
+
this.registry.register_fiber(fiberId, parentId ?? 0, scopeId ?? 0, Date.now());
|
|
1193
1193
|
}
|
|
1194
1194
|
markQueued(fiberId) {
|
|
1195
1195
|
this.registry.mark_queued(fiberId, Date.now());
|
|
@@ -1273,25 +1273,25 @@ function codeToStatus(code) {
|
|
|
1273
1273
|
|
|
1274
1274
|
// src/core/runtime/engine/WasmFiberEngine.ts
|
|
1275
1275
|
var DEFAULT_BUDGET = 4096;
|
|
1276
|
-
var WasmFiberEngine =
|
|
1277
|
-
constructor(runtime, options = {}) {
|
|
1276
|
+
var WasmFiberEngine = class {
|
|
1277
|
+
constructor(runtime, options = {}) {
|
|
1278
1278
|
this.runtime = runtime;
|
|
1279
|
-
this.bridge =
|
|
1279
|
+
this.bridge = options.bridge ?? (options.reference ? new ReferenceWasmBridge() : new WasmPackFiberBridge(options.modulePath));
|
|
1280
1280
|
this.kind = this.bridge.kind;
|
|
1281
1281
|
this.fiberRegistry = this.kind === "wasm" ? new WasmFiberRegistryBridge() : void 0;
|
|
1282
1282
|
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1283
|
+
runtime;
|
|
1284
|
+
kind;
|
|
1285
|
+
bridge;
|
|
1286
|
+
startedFibers = 0;
|
|
1287
|
+
runningFibers = 0;
|
|
1288
|
+
suspendedFibers = 0;
|
|
1289
|
+
completedFibers = 0;
|
|
1290
|
+
failedFibers = 0;
|
|
1291
|
+
interruptedFibers = 0;
|
|
1292
|
+
pendingHostEffects = 0;
|
|
1293
|
+
states = /* @__PURE__ */ new Map();
|
|
1294
|
+
fiberRegistry;
|
|
1295
1295
|
fork(effect, scopeId) {
|
|
1296
1296
|
const builder = new ProgramBuilder();
|
|
1297
1297
|
const compiled = builder.compile(effect);
|
|
@@ -1302,8 +1302,8 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1302
1302
|
this.runtime,
|
|
1303
1303
|
(id) => this.scheduleWakeup(id),
|
|
1304
1304
|
(id, reason) => this.interruptById(id, reason),
|
|
1305
|
-
(id) =>
|
|
1306
|
-
(id) =>
|
|
1305
|
+
(id) => this.fiberRegistry?.addJoiner(id),
|
|
1306
|
+
(id) => this.fiberRegistry?.markQueued(id)
|
|
1307
1307
|
);
|
|
1308
1308
|
if (scopeId !== void 0) handle.scopeId = scopeId;
|
|
1309
1309
|
const state = {
|
|
@@ -1318,7 +1318,7 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1318
1318
|
pendingCleanups: /* @__PURE__ */ new Set()
|
|
1319
1319
|
};
|
|
1320
1320
|
this.states.set(fiberId, state);
|
|
1321
|
-
|
|
1321
|
+
this.fiberRegistry?.registerFiber(fiberId, void 0, scopeId);
|
|
1322
1322
|
this.startedFibers += 1;
|
|
1323
1323
|
this.runningFibers += 1;
|
|
1324
1324
|
return handle;
|
|
@@ -1338,7 +1338,7 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1338
1338
|
pendingHostEffects: this.pendingHostEffects,
|
|
1339
1339
|
hostRegistryRefs: hostRefs,
|
|
1340
1340
|
wasm: this.bridge.stats(),
|
|
1341
|
-
fiberRegistry:
|
|
1341
|
+
fiberRegistry: this.fiberRegistry?.stats()
|
|
1342
1342
|
};
|
|
1343
1343
|
}
|
|
1344
1344
|
async shutdown() {
|
|
@@ -1365,13 +1365,13 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1365
1365
|
driveById(fiberId) {
|
|
1366
1366
|
const state = this.states.get(fiberId);
|
|
1367
1367
|
if (!state || state.completed) return;
|
|
1368
|
-
|
|
1368
|
+
this.fiberRegistry?.markRunning(fiberId);
|
|
1369
1369
|
withCurrentFiber(state.handle, () => this.drive(state));
|
|
1370
1370
|
}
|
|
1371
1371
|
drive(state, initialEvent) {
|
|
1372
1372
|
if (state.completed) return;
|
|
1373
1373
|
let budget = DEFAULT_BUDGET;
|
|
1374
|
-
let event =
|
|
1374
|
+
let event = initialEvent ?? this.bridge.poll(state.fiberId);
|
|
1375
1375
|
state.status = "running";
|
|
1376
1376
|
state.handle.setEngineStatus("running");
|
|
1377
1377
|
while (!state.completed && budget-- > 0) {
|
|
@@ -1505,7 +1505,7 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1505
1505
|
done = true;
|
|
1506
1506
|
try {
|
|
1507
1507
|
canceler();
|
|
1508
|
-
} catch
|
|
1508
|
+
} catch {
|
|
1509
1509
|
}
|
|
1510
1510
|
state.pendingCleanups.delete(cancelCleanup);
|
|
1511
1511
|
};
|
|
@@ -1601,7 +1601,7 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1601
1601
|
if (state.status !== "suspended") {
|
|
1602
1602
|
this.suspendedFibers += 1;
|
|
1603
1603
|
state.status = "suspended";
|
|
1604
|
-
|
|
1604
|
+
this.fiberRegistry?.markSuspended(state.fiberId);
|
|
1605
1605
|
state.handle.setEngineStatus("suspended");
|
|
1606
1606
|
state.handle.emit({ type: "fiber.suspend", fiberId: state.fiberId, reason });
|
|
1607
1607
|
}
|
|
@@ -1610,7 +1610,7 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1610
1610
|
if (state.status === "suspended") {
|
|
1611
1611
|
this.suspendedFibers = Math.max(0, this.suspendedFibers - 1);
|
|
1612
1612
|
state.status = "running";
|
|
1613
|
-
|
|
1613
|
+
this.fiberRegistry?.markRunning(state.fiberId);
|
|
1614
1614
|
state.handle.setEngineStatus("running");
|
|
1615
1615
|
state.handle.emit({ type: "fiber.resume", fiberId: state.fiberId });
|
|
1616
1616
|
}
|
|
@@ -1619,7 +1619,7 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1619
1619
|
if (state.completed) return;
|
|
1620
1620
|
state.completed = true;
|
|
1621
1621
|
state.status = "done";
|
|
1622
|
-
|
|
1622
|
+
this.fiberRegistry?.markDone(state.fiberId, "done");
|
|
1623
1623
|
this.completedFibers += 1;
|
|
1624
1624
|
this.cleanupState(state);
|
|
1625
1625
|
state.handle.succeed(value);
|
|
@@ -1628,7 +1628,7 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1628
1628
|
if (state.completed) return;
|
|
1629
1629
|
state.completed = true;
|
|
1630
1630
|
state.status = "failed";
|
|
1631
|
-
|
|
1631
|
+
this.fiberRegistry?.markDone(state.fiberId, "failed");
|
|
1632
1632
|
this.failedFibers += 1;
|
|
1633
1633
|
this.cleanupState(state);
|
|
1634
1634
|
state.handle.fail(error);
|
|
@@ -1637,7 +1637,7 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1637
1637
|
if (state.completed) return;
|
|
1638
1638
|
state.completed = true;
|
|
1639
1639
|
state.status = "failed";
|
|
1640
|
-
|
|
1640
|
+
this.fiberRegistry?.markDone(state.fiberId, "failed");
|
|
1641
1641
|
this.failedFibers += 1;
|
|
1642
1642
|
this.cleanupState(state);
|
|
1643
1643
|
state.handle.die(defect);
|
|
@@ -1646,7 +1646,7 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1646
1646
|
if (state.completed) return;
|
|
1647
1647
|
state.completed = true;
|
|
1648
1648
|
state.status = "interrupted";
|
|
1649
|
-
|
|
1649
|
+
this.fiberRegistry?.markDone(state.fiberId, "interrupted");
|
|
1650
1650
|
this.interruptedFibers += 1;
|
|
1651
1651
|
this.cleanupState(state);
|
|
1652
1652
|
state.handle.interrupted();
|
|
@@ -1657,22 +1657,22 @@ var WasmFiberEngine = (_class13 = class {
|
|
|
1657
1657
|
for (const cleanup of Array.from(state.pendingCleanups)) cleanup();
|
|
1658
1658
|
state.pendingCleanups.clear();
|
|
1659
1659
|
this.bridge.dropFiber(state.fiberId);
|
|
1660
|
-
|
|
1660
|
+
this.fiberRegistry?.dropFiber(state.fiberId);
|
|
1661
1661
|
state.registry.clear();
|
|
1662
1662
|
this.states.delete(state.fiberId);
|
|
1663
1663
|
}
|
|
1664
|
-
}
|
|
1664
|
+
};
|
|
1665
1665
|
|
|
1666
1666
|
// src/core/runtime/capabilities.ts
|
|
1667
1667
|
function runtimeCapabilities() {
|
|
1668
1668
|
const mod = resolveWasmModule();
|
|
1669
1669
|
return {
|
|
1670
1670
|
wasmAvailable: !!mod,
|
|
1671
|
-
wasmFiberEngine: typeof
|
|
1672
|
-
wasmRingBuffer: typeof
|
|
1673
|
-
wasmScheduler: typeof
|
|
1674
|
-
wasmFiberRegistry: typeof
|
|
1675
|
-
wasmStreamChunks: typeof
|
|
1671
|
+
wasmFiberEngine: typeof mod?.BrassWasmVm === "function",
|
|
1672
|
+
wasmRingBuffer: typeof mod?.BrassWasmRingBuffer === "function",
|
|
1673
|
+
wasmScheduler: typeof mod?.BrassWasmSchedulerStateMachine === "function",
|
|
1674
|
+
wasmFiberRegistry: typeof mod?.BrassWasmFiberRegistry === "function",
|
|
1675
|
+
wasmStreamChunks: typeof mod?.BrassWasmChunkBuffer === "function"
|
|
1676
1676
|
};
|
|
1677
1677
|
}
|
|
1678
1678
|
|
|
@@ -1682,23 +1682,23 @@ var NoopHooks = {
|
|
|
1682
1682
|
}
|
|
1683
1683
|
};
|
|
1684
1684
|
var Runtime = class _Runtime {
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1685
|
+
env;
|
|
1686
|
+
scheduler;
|
|
1687
|
+
hooks;
|
|
1688
|
+
hostExecutor;
|
|
1689
|
+
engineMode;
|
|
1690
|
+
wasmOptions;
|
|
1691
|
+
fiberEngine;
|
|
1692
|
+
fallbackUsed;
|
|
1693
|
+
forkPolicy;
|
|
1694
1694
|
// opcional: registry para observabilidad
|
|
1695
|
-
|
|
1695
|
+
registry;
|
|
1696
1696
|
constructor(args) {
|
|
1697
1697
|
this.env = args.env;
|
|
1698
|
-
this.scheduler =
|
|
1699
|
-
this.hooks =
|
|
1700
|
-
this.hostExecutor =
|
|
1701
|
-
this.engineMode =
|
|
1698
|
+
this.scheduler = args.scheduler ?? globalScheduler;
|
|
1699
|
+
this.hooks = args.hooks ?? NoopHooks;
|
|
1700
|
+
this.hostExecutor = args.hostExecutor ?? DefaultHostExecutor;
|
|
1701
|
+
this.engineMode = args.engine ?? "auto";
|
|
1702
1702
|
this.wasmOptions = args.wasm;
|
|
1703
1703
|
this.forkPolicy = makeForkPolicy(this.env, this.hooks);
|
|
1704
1704
|
const selected = this.makeFiberEngine(this.engineMode, args.wasm);
|
|
@@ -1714,7 +1714,7 @@ var Runtime = class _Runtime {
|
|
|
1714
1714
|
if (capabilities.wasmFiberEngine) {
|
|
1715
1715
|
return { engine: new WasmFiberEngine(this, wasm), fallbackUsed: false };
|
|
1716
1716
|
}
|
|
1717
|
-
} catch
|
|
1717
|
+
} catch {
|
|
1718
1718
|
}
|
|
1719
1719
|
return { engine: new JsFiberEngine(this), fallbackUsed: true };
|
|
1720
1720
|
}
|
|
@@ -1737,11 +1737,11 @@ var Runtime = class _Runtime {
|
|
|
1737
1737
|
if (this.hooks === NoopHooks) return;
|
|
1738
1738
|
const f = getCurrentFiber();
|
|
1739
1739
|
const ctx = {
|
|
1740
|
-
fiberId:
|
|
1741
|
-
scopeId:
|
|
1740
|
+
fiberId: f?.id,
|
|
1741
|
+
scopeId: f?.scopeId,
|
|
1742
1742
|
// ✅ FIX: era f?.scope
|
|
1743
|
-
traceId:
|
|
1744
|
-
spanId:
|
|
1743
|
+
traceId: f?.fiberContext?.trace?.traceId,
|
|
1744
|
+
spanId: f?.fiberContext?.trace?.spanId
|
|
1745
1745
|
};
|
|
1746
1746
|
this.hooks.emit(ev, ctx);
|
|
1747
1747
|
}
|
|
@@ -1753,7 +1753,7 @@ var Runtime = class _Runtime {
|
|
|
1753
1753
|
const fiber = this.fiberEngine.fork(effect, scopeId);
|
|
1754
1754
|
if (scopeId !== void 0) fiber.scopeId = scopeId;
|
|
1755
1755
|
this.forkPolicy.initChild(fiber, parent, scopeId);
|
|
1756
|
-
|
|
1756
|
+
fiber.schedule?.("initial-step");
|
|
1757
1757
|
return fiber;
|
|
1758
1758
|
}
|
|
1759
1759
|
stats() {
|
|
@@ -1765,7 +1765,7 @@ var Runtime = class _Runtime {
|
|
|
1765
1765
|
return runtimeCapabilities();
|
|
1766
1766
|
}
|
|
1767
1767
|
shutdown() {
|
|
1768
|
-
return
|
|
1768
|
+
return this.fiberEngine.shutdown?.();
|
|
1769
1769
|
}
|
|
1770
1770
|
unsafeRunAsync(effect, cb) {
|
|
1771
1771
|
const fiber = this.fork(effect);
|
|
@@ -1778,7 +1778,7 @@ var Runtime = class _Runtime {
|
|
|
1778
1778
|
if (exit._tag === "Success") resolve(exit.value);
|
|
1779
1779
|
else {
|
|
1780
1780
|
const c = exit.cause;
|
|
1781
|
-
if (
|
|
1781
|
+
if (c?._tag === "Fail") reject(c.error);
|
|
1782
1782
|
else reject(new Error("Interrupted"));
|
|
1783
1783
|
}
|
|
1784
1784
|
});
|
|
@@ -1810,13 +1810,13 @@ var Runtime = class _Runtime {
|
|
|
1810
1810
|
}
|
|
1811
1811
|
};
|
|
1812
1812
|
function fork(effect, env) {
|
|
1813
|
-
return Runtime.make(
|
|
1813
|
+
return Runtime.make(env ?? {}).fork(effect);
|
|
1814
1814
|
}
|
|
1815
1815
|
function unsafeRunAsync(effect, env, cb) {
|
|
1816
|
-
Runtime.make(
|
|
1816
|
+
Runtime.make(env ?? {}).unsafeRunAsync(effect, cb);
|
|
1817
1817
|
}
|
|
1818
1818
|
function toPromise(effect, env) {
|
|
1819
|
-
return Runtime.make(
|
|
1819
|
+
return Runtime.make(env ?? {}).toPromise(effect);
|
|
1820
1820
|
}
|
|
1821
1821
|
function fromPromiseAbortable(make, onReject) {
|
|
1822
1822
|
return {
|
|
@@ -1873,7 +1873,7 @@ function getBenchmarkBudget() {
|
|
|
1873
1873
|
}
|
|
1874
1874
|
function reassociateFlatMap(cur) {
|
|
1875
1875
|
let current = cur;
|
|
1876
|
-
while (current._tag === "FlatMap" &&
|
|
1876
|
+
while (current._tag === "FlatMap" && current.first?._tag === "FlatMap") {
|
|
1877
1877
|
const inner = current.first;
|
|
1878
1878
|
const g = current.andThen;
|
|
1879
1879
|
current = {
|
|
@@ -1888,32 +1888,32 @@ function reassociateFlatMap(cur) {
|
|
|
1888
1888
|
}
|
|
1889
1889
|
return current;
|
|
1890
1890
|
}
|
|
1891
|
-
var RuntimeFiber =
|
|
1892
|
-
|
|
1891
|
+
var RuntimeFiber = class {
|
|
1892
|
+
id;
|
|
1893
1893
|
// 👇 CLAVE: guardar el runtime en el fiber (para getCurrentRuntime())
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1894
|
+
runtime;
|
|
1895
|
+
closing = null;
|
|
1896
|
+
finishing = false;
|
|
1897
|
+
runState = RUN.RUNNING;
|
|
1898
|
+
interrupted = false;
|
|
1899
|
+
result = null;
|
|
1900
|
+
joiners = [];
|
|
1901
1901
|
// estado de evaluación
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1902
|
+
current;
|
|
1903
|
+
stack = [];
|
|
1904
|
+
fiberFinalizers = [];
|
|
1905
|
+
finalizersDrained = false;
|
|
1906
|
+
fiberContext;
|
|
1907
|
+
name;
|
|
1908
|
+
scopeId;
|
|
1909
1909
|
/**
|
|
1910
1910
|
* Cached closure for the scheduler callback — avoids creating a new
|
|
1911
1911
|
* closure on every `schedule()` call. The tag parameter used by the
|
|
1912
1912
|
* scheduler is only part of the label string, not the callback logic,
|
|
1913
1913
|
* so a single cached closure is sufficient.
|
|
1914
1914
|
*/
|
|
1915
|
-
|
|
1916
|
-
constructor(runtime, effect) {
|
|
1915
|
+
boundStep;
|
|
1916
|
+
constructor(runtime, effect) {
|
|
1917
1917
|
this.id = nextId++;
|
|
1918
1918
|
this.runtime = runtime;
|
|
1919
1919
|
this.current = effect;
|
|
@@ -1942,14 +1942,14 @@ var RuntimeFiber = (_class14 = class {
|
|
|
1942
1942
|
return this.runtime.env;
|
|
1943
1943
|
}
|
|
1944
1944
|
get scheduler() {
|
|
1945
|
-
return
|
|
1945
|
+
return this.runtime.scheduler ?? globalScheduler;
|
|
1946
1946
|
}
|
|
1947
1947
|
emit(ev) {
|
|
1948
1948
|
this.runtime.hooks.emit(ev, {
|
|
1949
1949
|
fiberId: this.id,
|
|
1950
1950
|
scopeId: this.scopeId,
|
|
1951
|
-
traceId:
|
|
1952
|
-
spanId:
|
|
1951
|
+
traceId: this.fiberContext?.trace?.traceId,
|
|
1952
|
+
spanId: this.fiberContext?.trace?.spanId
|
|
1953
1953
|
});
|
|
1954
1954
|
}
|
|
1955
1955
|
addFinalizer(f) {
|
|
@@ -1992,7 +1992,7 @@ var RuntimeFiber = (_class14 = class {
|
|
|
1992
1992
|
unsafeRunAsync(eff, this.env, () => {
|
|
1993
1993
|
});
|
|
1994
1994
|
}
|
|
1995
|
-
} catch
|
|
1995
|
+
} catch {
|
|
1996
1996
|
}
|
|
1997
1997
|
}
|
|
1998
1998
|
}
|
|
@@ -2048,14 +2048,14 @@ var RuntimeFiber = (_class14 = class {
|
|
|
2048
2048
|
}
|
|
2049
2049
|
this.notify(Exit.failCause(Cause.fail(error)));
|
|
2050
2050
|
}
|
|
2051
|
-
|
|
2051
|
+
budget = DEFAULT_BUDGET2;
|
|
2052
2052
|
step() {
|
|
2053
2053
|
if (this.result != null) return STEP.DONE;
|
|
2054
2054
|
if (this.interrupted) {
|
|
2055
2055
|
this.notify(Exit.failCause(Cause.interrupt()));
|
|
2056
2056
|
return STEP.DONE;
|
|
2057
2057
|
}
|
|
2058
|
-
this.budget =
|
|
2058
|
+
this.budget = __benchmarkBudget ?? DEFAULT_BUDGET2;
|
|
2059
2059
|
while (this.budget-- > 0) {
|
|
2060
2060
|
this.current = reassociateFlatMap(this.current);
|
|
2061
2061
|
const current = this.current;
|
|
@@ -2139,7 +2139,7 @@ var RuntimeFiber = (_class14 = class {
|
|
|
2139
2139
|
done = true;
|
|
2140
2140
|
try {
|
|
2141
2141
|
canceler();
|
|
2142
|
-
} catch
|
|
2142
|
+
} catch {
|
|
2143
2143
|
}
|
|
2144
2144
|
});
|
|
2145
2145
|
}
|
|
@@ -2168,13 +2168,13 @@ var RuntimeFiber = (_class14 = class {
|
|
|
2168
2168
|
}
|
|
2169
2169
|
return STEP.CONTINUE;
|
|
2170
2170
|
}
|
|
2171
|
-
}
|
|
2171
|
+
};
|
|
2172
2172
|
function getCurrentFiber() {
|
|
2173
2173
|
return _current;
|
|
2174
2174
|
}
|
|
2175
2175
|
function unsafeGetCurrentRuntime() {
|
|
2176
2176
|
const f = getCurrentFiber();
|
|
2177
|
-
if (!
|
|
2177
|
+
if (!f?.runtime) {
|
|
2178
2178
|
throw new Error("unsafeGetCurrentRuntime: no current fiber/runtime");
|
|
2179
2179
|
}
|
|
2180
2180
|
return f.runtime;
|
|
@@ -2206,12 +2206,12 @@ function awaitAll(fibers) {
|
|
|
2206
2206
|
}
|
|
2207
2207
|
});
|
|
2208
2208
|
}
|
|
2209
|
-
var Scope =
|
|
2210
|
-
constructor(runtime, parentScopeId) {
|
|
2209
|
+
var Scope = class _Scope {
|
|
2210
|
+
constructor(runtime, parentScopeId) {
|
|
2211
2211
|
this.runtime = runtime;
|
|
2212
2212
|
this.parentScopeId = parentScopeId;
|
|
2213
2213
|
this.id = nextScopeId++;
|
|
2214
|
-
const inferredParent =
|
|
2214
|
+
const inferredParent = this.parentScopeId ?? getCurrentFiber()?.scopeId;
|
|
2215
2215
|
if (this.runtime.hasActiveHooks()) {
|
|
2216
2216
|
this.runtime.emit({
|
|
2217
2217
|
type: "scope.open",
|
|
@@ -2220,13 +2220,13 @@ var Scope = (_class15 = class _Scope {
|
|
|
2220
2220
|
});
|
|
2221
2221
|
}
|
|
2222
2222
|
}
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2223
|
+
runtime;
|
|
2224
|
+
parentScopeId;
|
|
2225
|
+
id;
|
|
2226
|
+
closed = false;
|
|
2227
|
+
children = /* @__PURE__ */ new Set();
|
|
2228
|
+
subScopes = /* @__PURE__ */ new Set();
|
|
2229
|
+
finalizers = [];
|
|
2230
2230
|
/** registra un finalizer (LIFO) */
|
|
2231
2231
|
addFinalizer(f) {
|
|
2232
2232
|
if (this.closed) {
|
|
@@ -2285,7 +2285,7 @@ var Scope = (_class15 = class _Scope {
|
|
|
2285
2285
|
let result;
|
|
2286
2286
|
try {
|
|
2287
2287
|
result = fin(exit);
|
|
2288
|
-
} catch
|
|
2288
|
+
} catch {
|
|
2289
2289
|
return unit();
|
|
2290
2290
|
}
|
|
2291
2291
|
if (result._tag === "Succeed") {
|
|
@@ -2336,7 +2336,7 @@ var Scope = (_class15 = class _Scope {
|
|
|
2336
2336
|
})
|
|
2337
2337
|
);
|
|
2338
2338
|
}
|
|
2339
|
-
}
|
|
2339
|
+
};
|
|
2340
2340
|
function withScopeAsync(runtime, f) {
|
|
2341
2341
|
return async((_env, cb) => {
|
|
2342
2342
|
const scope = new Scope(runtime);
|
|
@@ -2486,71 +2486,71 @@ function raceWith(left, right, parentScope, onLeft, onRight) {
|
|
|
2486
2486
|
});
|
|
2487
2487
|
}
|
|
2488
2488
|
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2489
|
+
export {
|
|
2490
|
+
Async,
|
|
2491
|
+
asyncFold,
|
|
2492
|
+
asyncCatchAll,
|
|
2493
|
+
asyncMapError,
|
|
2494
|
+
unit,
|
|
2495
|
+
asyncSucceed,
|
|
2496
|
+
asyncFail,
|
|
2497
|
+
asyncSync,
|
|
2498
|
+
asyncTotal,
|
|
2499
|
+
async,
|
|
2500
|
+
asyncMap,
|
|
2501
|
+
asyncFlatMap,
|
|
2502
|
+
acquireRelease,
|
|
2503
|
+
asyncInterruptible,
|
|
2504
|
+
withAsyncPromise,
|
|
2505
|
+
mapAsync,
|
|
2506
|
+
mapTryAsync,
|
|
2507
|
+
none,
|
|
2508
|
+
some,
|
|
2509
|
+
Cause,
|
|
2510
|
+
Exit,
|
|
2511
|
+
succeed,
|
|
2512
|
+
fail,
|
|
2513
|
+
sync,
|
|
2514
|
+
map,
|
|
2515
|
+
flatMap,
|
|
2516
|
+
mapError,
|
|
2517
|
+
catchAll,
|
|
2518
|
+
orElseOptional,
|
|
2519
|
+
end,
|
|
2520
|
+
PushStatus,
|
|
2521
|
+
RingBuffer,
|
|
2522
|
+
resolveWasmModule,
|
|
2523
|
+
makeBoundedRingBuffer,
|
|
2524
|
+
Scheduler,
|
|
2525
|
+
globalScheduler,
|
|
2526
|
+
setBenchmarkBudget,
|
|
2527
|
+
getBenchmarkBudget,
|
|
2528
|
+
RuntimeFiber,
|
|
2529
|
+
getCurrentFiber,
|
|
2530
|
+
unsafeGetCurrentRuntime,
|
|
2531
|
+
withCurrentFiber,
|
|
2532
|
+
DefaultHostExecutor,
|
|
2533
|
+
JsFiberEngine,
|
|
2534
|
+
HostRegistry,
|
|
2535
|
+
ProgramBuilder,
|
|
2536
|
+
EngineFiberHandle,
|
|
2537
|
+
ReferenceWasmBridge,
|
|
2538
|
+
WasmPackFiberBridge,
|
|
2539
|
+
WasmFiberRegistryBridge,
|
|
2540
|
+
WasmFiberEngine,
|
|
2541
|
+
runtimeCapabilities,
|
|
2542
|
+
NoopHooks,
|
|
2543
|
+
Runtime,
|
|
2544
|
+
fork,
|
|
2545
|
+
unsafeRunAsync,
|
|
2546
|
+
toPromise,
|
|
2547
|
+
fromPromiseAbortable,
|
|
2548
|
+
unsafeRunFoldWithEnv,
|
|
2549
|
+
Scope,
|
|
2550
|
+
withScopeAsync,
|
|
2551
|
+
withScope,
|
|
2552
|
+
race,
|
|
2553
|
+
zipPar,
|
|
2554
|
+
collectAllPar,
|
|
2555
|
+
raceWith
|
|
2556
|
+
};
|