brass-runtime 1.13.8 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/dist/agent/cli/main.cjs +44 -43
- package/dist/agent/cli/main.js +5 -4
- package/dist/agent/cli/main.mjs +5 -4
- package/dist/agent/index.cjs +4 -3
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +3 -2
- package/dist/agent/index.mjs +3 -2
- package/dist/{chunk-3R7ZYRK2.mjs → chunk-3QMOKAS5.js} +9 -7
- package/dist/{chunk-ATHSSDUF.js → chunk-4NHES7VK.mjs} +113 -31
- package/dist/chunk-AR22SXML.js +1043 -0
- package/dist/chunk-BDF4AMWX.mjs +3773 -0
- package/dist/chunk-BDYEENHT.js +224 -0
- package/dist/chunk-BMH5AV44.js +3773 -0
- package/dist/chunk-ELOOF35R.mjs +131 -0
- package/dist/chunk-JFPU5GQI.mjs +1043 -0
- package/dist/{chunk-INZBKOHY.js → chunk-K6M7MDZ4.mjs} +9 -7
- package/dist/chunk-MS34J5LY.cjs +224 -0
- package/dist/{chunk-XNOTJSMZ.mjs → chunk-PPUXIH5R.js} +113 -31
- package/dist/chunk-R3R2FVLG.cjs +131 -0
- package/dist/{chunk-ZTDK2DLG.cjs → chunk-STVLQ3XD.cjs} +169 -87
- package/dist/chunk-TGIFUAK4.cjs +3773 -0
- package/dist/chunk-TO7IKXYT.js +131 -0
- package/dist/chunk-UMAZLXAB.mjs +224 -0
- package/dist/{chunk-XDINDYNA.cjs → chunk-VEZNF5GZ.cjs} +136 -134
- package/dist/chunk-XPZNXSVN.cjs +1043 -0
- package/dist/core/index.cjs +216 -0
- package/dist/core/index.d.ts +673 -0
- package/dist/core/index.js +216 -0
- package/dist/core/index.mjs +216 -0
- package/dist/{effect-ISvXPLgc.d.ts → effect-CMOQKX8y.d.ts} +202 -31
- package/dist/http/index.cjs +3177 -187
- package/dist/http/index.d.ts +1692 -9
- package/dist/http/index.js +3164 -174
- package/dist/http/index.mjs +3164 -174
- package/dist/index.cjs +936 -219
- package/dist/index.d.ts +313 -36
- package/dist/index.js +830 -113
- package/dist/index.mjs +830 -113
- package/dist/{stream-BvukHxCv.d.ts → stream-FQm9h4Mg.d.ts} +12 -4
- package/dist/tracing-DNT9jEbr.d.ts +106 -0
- package/package.json +11 -3
- package/wasm/pkg/brass_runtime_wasm_engine.d.ts +95 -16
- package/wasm/pkg/brass_runtime_wasm_engine.js +715 -15
- package/wasm/pkg/brass_runtime_wasm_engine_bg.wasm +0 -0
- package/wasm/pkg/brass_runtime_wasm_engine_bg.wasm.d.ts +78 -7
- package/dist/chunk-2P4PD6D7.cjs +0 -2557
- package/dist/chunk-7F2R7A2V.mjs +0 -2557
- package/dist/chunk-L6KKKM66.js +0 -2557
|
@@ -25,6 +25,8 @@ type RuntimeCapabilities = {
|
|
|
25
25
|
wasmRingBuffer: boolean;
|
|
26
26
|
wasmScheduler: boolean;
|
|
27
27
|
wasmFiberRegistry: boolean;
|
|
28
|
+
wasmFiberReadyQueue: boolean;
|
|
29
|
+
wasmBinaryAbi: boolean;
|
|
28
30
|
wasmStreamChunks: boolean;
|
|
29
31
|
};
|
|
30
32
|
declare function runtimeCapabilities(): RuntimeCapabilities;
|
|
@@ -50,17 +52,17 @@ declare class RingBuffer<T> {
|
|
|
50
52
|
private grow;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
type EngineKind = "
|
|
55
|
+
type EngineKind = "ts" | "wasm";
|
|
54
56
|
type EngineStats<T> = {
|
|
55
57
|
engine: EngineKind;
|
|
56
58
|
data: T;
|
|
57
|
-
fallbackUsed:
|
|
59
|
+
fallbackUsed: false;
|
|
58
60
|
};
|
|
59
|
-
type EngineSelectionMode =
|
|
61
|
+
type EngineSelectionMode = EngineKind;
|
|
60
62
|
type EngineSelection<T> = EngineStats<T> & {
|
|
61
63
|
requested: EngineSelectionMode;
|
|
62
64
|
};
|
|
63
|
-
declare function engineStats<T>(engine: EngineKind, data: T
|
|
65
|
+
declare function engineStats<T>(engine: EngineKind, data: T): EngineStats<T>;
|
|
64
66
|
declare function selectedEngineStats<T>(requested: EngineSelectionMode, engine: EngineKind, data: T): EngineSelection<T>;
|
|
65
67
|
|
|
66
68
|
type RingBufferStatsData = {
|
|
@@ -74,7 +76,7 @@ type RingBufferStatsData = {
|
|
|
74
76
|
type RingLike<T> = {
|
|
75
77
|
readonly length: number;
|
|
76
78
|
readonly capacity: number;
|
|
77
|
-
readonly engine: "
|
|
79
|
+
readonly engine: "ts" | "wasm";
|
|
78
80
|
readonly fallbackUsed: boolean;
|
|
79
81
|
isEmpty(): boolean;
|
|
80
82
|
push(value: T): PushStatus;
|
|
@@ -82,14 +84,23 @@ type RingLike<T> = {
|
|
|
82
84
|
clear(): void;
|
|
83
85
|
stats(): EngineStats<RingBufferStatsData>;
|
|
84
86
|
};
|
|
85
|
-
type RingBufferEngine = "
|
|
87
|
+
type RingBufferEngine = "ts" | "wasm";
|
|
86
88
|
type RingBufferOptions = {
|
|
87
89
|
engine?: RingBufferEngine;
|
|
88
90
|
};
|
|
89
91
|
declare function makeBoundedRingBuffer<T>(initialCapacity: number, maxCapacity?: number, options?: RingBufferOptions): RingLike<T>;
|
|
90
92
|
|
|
91
93
|
type Task = () => void;
|
|
92
|
-
type
|
|
94
|
+
type ScheduleResult = "accepted" | "dropped";
|
|
95
|
+
type SchedulerEngine = "ts" | "wasm";
|
|
96
|
+
type LaneStatsData = {
|
|
97
|
+
key: string;
|
|
98
|
+
len: number;
|
|
99
|
+
capacity: number;
|
|
100
|
+
enqueuedTasks: number;
|
|
101
|
+
executedTasks: number;
|
|
102
|
+
droppedTasks: number;
|
|
103
|
+
};
|
|
93
104
|
type SchedulerStatsData = {
|
|
94
105
|
len: number;
|
|
95
106
|
capacity?: number;
|
|
@@ -100,6 +111,7 @@ type SchedulerStatsData = {
|
|
|
100
111
|
executedTasks?: number;
|
|
101
112
|
droppedTasks?: number;
|
|
102
113
|
yieldedByBudget?: number;
|
|
114
|
+
lanes?: LaneStatsData[];
|
|
103
115
|
};
|
|
104
116
|
type SchedulerStats = EngineStats<SchedulerStatsData>;
|
|
105
117
|
type SchedulerOptions = RingBufferOptions & {
|
|
@@ -108,23 +120,48 @@ type SchedulerOptions = RingBufferOptions & {
|
|
|
108
120
|
maxCapacity?: number;
|
|
109
121
|
flushBudget?: number;
|
|
110
122
|
microThreshold?: number;
|
|
111
|
-
|
|
123
|
+
/** Capacity per inferred caller lane. Overflow drops the newly enqueued task in that lane. */
|
|
124
|
+
laneCapacity?: number;
|
|
125
|
+
/** Max tasks a single lane can run before rotating to the next lane. */
|
|
126
|
+
laneBudget?: number;
|
|
127
|
+
/** Safety cap for distinct lanes. New lanes past this limit go to `overflow`. */
|
|
128
|
+
maxLanes?: number;
|
|
129
|
+
};
|
|
130
|
+
declare function sanitizeLaneKey(value: string): string;
|
|
131
|
+
declare function laneTag(lane: string, tag?: string): string;
|
|
132
|
+
/**
|
|
133
|
+
* Infers a logical caller lane from the first non-Brass frame in the stack.
|
|
134
|
+
* This keeps Brass implementation-agnostic: the first task/fiber gets a stable
|
|
135
|
+
* key derived from the upper layer that invoked the runtime, and children inherit it.
|
|
136
|
+
*/
|
|
137
|
+
declare function inferCallerLaneFromStack(stack?: string | undefined, fallback?: string): string;
|
|
112
138
|
declare class Scheduler {
|
|
113
139
|
private readonly engine;
|
|
114
140
|
private readonly js?;
|
|
115
141
|
private readonly wasm?;
|
|
116
142
|
private readonly flushBudget;
|
|
117
143
|
private readonly microThreshold;
|
|
144
|
+
private readonly laneCapacity;
|
|
145
|
+
private readonly laneBudget;
|
|
146
|
+
private readonly maxLanes;
|
|
118
147
|
private readonly fallbackUsed;
|
|
119
148
|
private readonly boundFlush;
|
|
120
149
|
constructor(options?: SchedulerOptions);
|
|
121
|
-
schedule(task: Task, tag?: string):
|
|
150
|
+
schedule(task: Task, tag?: string): ScheduleResult;
|
|
151
|
+
scheduleBatch(tasks: Array<{
|
|
152
|
+
fn: Task;
|
|
153
|
+
tag: string;
|
|
154
|
+
}>): ScheduleResult[];
|
|
122
155
|
stats(): SchedulerStats;
|
|
123
156
|
private scheduleWasm;
|
|
157
|
+
private scheduleBatchWasm;
|
|
158
|
+
private getOrCreateLane;
|
|
159
|
+
private createLane;
|
|
124
160
|
private scheduleJs;
|
|
125
161
|
private requestFlush;
|
|
126
162
|
private flush;
|
|
127
163
|
private flushWasm;
|
|
164
|
+
private shiftFromNextLane;
|
|
128
165
|
private flushJs;
|
|
129
166
|
}
|
|
130
167
|
declare const globalScheduler: Scheduler;
|
|
@@ -338,15 +375,37 @@ type FlatMapRef<R = unknown> = (value: unknown) => Async<R, unknown, unknown>;
|
|
|
338
375
|
type FoldFailureRef<R = unknown> = (error: unknown) => Async<R, unknown, unknown>;
|
|
339
376
|
type FoldSuccessRef<R = unknown> = (value: unknown) => Async<R, unknown, unknown>;
|
|
340
377
|
type DecodeRef = (result: HostActionResult) => unknown;
|
|
378
|
+
type HostRegistryStats = {
|
|
379
|
+
readonly live: number;
|
|
380
|
+
readonly capacity: number;
|
|
381
|
+
readonly allocated: number;
|
|
382
|
+
readonly released: number;
|
|
383
|
+
readonly reused: number;
|
|
384
|
+
readonly staleReads: number;
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* Slab-backed registry for JS values referenced by the WASM VM.
|
|
388
|
+
*
|
|
389
|
+
* Refs are generational u32 handles: stale refs fail fast after a slot is
|
|
390
|
+
* released/reused. clear() releases all live slots, which is called when a
|
|
391
|
+
* fiber completes so callbacks, errors, decoders and intermediate values do not
|
|
392
|
+
* stay retained by the engine.
|
|
393
|
+
*/
|
|
341
394
|
declare class HostRegistry {
|
|
342
|
-
private
|
|
343
|
-
private readonly
|
|
395
|
+
private readonly slots;
|
|
396
|
+
private readonly free;
|
|
397
|
+
private live;
|
|
398
|
+
private allocated;
|
|
399
|
+
private released;
|
|
400
|
+
private reused;
|
|
401
|
+
private staleReads;
|
|
344
402
|
register<T>(value: T): RefId;
|
|
345
403
|
get<T>(ref: RefId): T;
|
|
346
404
|
set(ref: RefId, value: unknown): void;
|
|
347
405
|
delete(ref: RefId): void;
|
|
348
406
|
clear(): void;
|
|
349
407
|
size(): number;
|
|
408
|
+
stats(): HostRegistryStats;
|
|
350
409
|
}
|
|
351
410
|
type CompiledProgram = {
|
|
352
411
|
readonly program: OpcodeProgram;
|
|
@@ -361,8 +420,8 @@ declare class ProgramBuilder {
|
|
|
361
420
|
private visit;
|
|
362
421
|
}
|
|
363
422
|
|
|
364
|
-
type FiberEngineKind = "
|
|
365
|
-
type RuntimeEngineMode = FiberEngineKind
|
|
423
|
+
type FiberEngineKind = "ts" | "wasm";
|
|
424
|
+
type RuntimeEngineMode = FiberEngineKind;
|
|
366
425
|
type FiberEngineStats = {
|
|
367
426
|
readonly engine: string;
|
|
368
427
|
readonly startedFibers: number;
|
|
@@ -374,8 +433,11 @@ type FiberEngineStats = {
|
|
|
374
433
|
readonly interruptedFibers: number;
|
|
375
434
|
readonly pendingHostEffects: number;
|
|
376
435
|
readonly hostRegistryRefs?: number;
|
|
436
|
+
readonly hostRegistryStats?: unknown;
|
|
377
437
|
readonly wasm?: unknown;
|
|
378
438
|
readonly fiberRegistry?: unknown;
|
|
439
|
+
readonly readyQueue?: unknown;
|
|
440
|
+
readonly timerWheel?: unknown;
|
|
379
441
|
};
|
|
380
442
|
interface FiberEngine<R = unknown> {
|
|
381
443
|
readonly kind: FiberEngineKind;
|
|
@@ -389,7 +451,7 @@ type WasmEngineRuntime<R = unknown> = {
|
|
|
389
451
|
readonly env: R;
|
|
390
452
|
readonly hostExecutor: HostExecutor<R>;
|
|
391
453
|
readonly scheduler: {
|
|
392
|
-
schedule(task: () => void, label?: string):
|
|
454
|
+
schedule(task: () => void, label?: string): unknown;
|
|
393
455
|
};
|
|
394
456
|
readonly hooks: {
|
|
395
457
|
emit(ev: any, ctx: any): void;
|
|
@@ -446,13 +508,21 @@ type EngineEvent = {
|
|
|
446
508
|
readonly decodeRef?: RefId;
|
|
447
509
|
};
|
|
448
510
|
interface WasmBridge {
|
|
449
|
-
readonly kind: "wasm"
|
|
511
|
+
readonly kind: "wasm";
|
|
512
|
+
readonly supportsBinary?: boolean;
|
|
513
|
+
readonly supportsZeroCopy?: boolean;
|
|
514
|
+
readonly supportsNoJsonMetrics?: boolean;
|
|
450
515
|
createFiber(program: OpcodeProgram): FiberId$1;
|
|
451
516
|
poll(fiberId: FiberId$1): EngineEvent;
|
|
517
|
+
driveBatch?(fiberId: FiberId$1, budget: number): readonly EngineEvent[];
|
|
452
518
|
provideValue(fiberId: FiberId$1, valueRef: RefId): EngineEvent;
|
|
519
|
+
provideValueBatch?(fiberId: FiberId$1, valueRef: RefId, budget: number): readonly EngineEvent[];
|
|
453
520
|
provideError(fiberId: FiberId$1, errorRef: RefId): EngineEvent;
|
|
521
|
+
provideErrorBatch?(fiberId: FiberId$1, errorRef: RefId, budget: number): readonly EngineEvent[];
|
|
454
522
|
provideEffect(fiberId: FiberId$1, root: NodeId, nodes: OpcodeNode[]): EngineEvent;
|
|
523
|
+
provideEffectBatch?(fiberId: FiberId$1, root: NodeId, nodes: OpcodeNode[], budget: number): readonly EngineEvent[];
|
|
455
524
|
interrupt(fiberId: FiberId$1, reasonRef: RefId): EngineEvent;
|
|
525
|
+
interruptBatch?(fiberId: FiberId$1, reasonRef: RefId, budget: number): readonly EngineEvent[];
|
|
456
526
|
dropFiber(fiberId: FiberId$1): void;
|
|
457
527
|
stats(): unknown;
|
|
458
528
|
}
|
|
@@ -461,12 +531,12 @@ type Joiner<E, A> = (exit: Exit<E, A>) => void;
|
|
|
461
531
|
type WasmFiberEngineOptions = {
|
|
462
532
|
readonly bridge?: WasmBridge;
|
|
463
533
|
readonly modulePath?: string;
|
|
464
|
-
readonly reference?: boolean;
|
|
465
534
|
};
|
|
466
535
|
declare class WasmFiberEngine<R> implements FiberEngine<R> {
|
|
467
536
|
private readonly runtime;
|
|
468
537
|
readonly kind: FiberEngineKind;
|
|
469
538
|
private readonly bridge;
|
|
539
|
+
private readonly readyQueue;
|
|
470
540
|
private startedFibers;
|
|
471
541
|
private runningFibers;
|
|
472
542
|
private suspendedFibers;
|
|
@@ -474,8 +544,12 @@ declare class WasmFiberEngine<R> implements FiberEngine<R> {
|
|
|
474
544
|
private failedFibers;
|
|
475
545
|
private interruptedFibers;
|
|
476
546
|
private pendingHostEffects;
|
|
547
|
+
private readyDrainScheduled;
|
|
548
|
+
private readyDraining;
|
|
477
549
|
private readonly states;
|
|
550
|
+
private readonly pendingResumes;
|
|
478
551
|
private readonly fiberRegistry?;
|
|
552
|
+
private readonly timerWheel?;
|
|
479
553
|
constructor(runtime: WasmEngineRuntime<R> & any, options?: WasmFiberEngineOptions);
|
|
480
554
|
fork<E, A>(effect: Async<R, E, A>, scopeId?: number): Fiber<E, A> & {
|
|
481
555
|
schedule?: (tag?: string) => void;
|
|
@@ -484,13 +558,21 @@ declare class WasmFiberEngine<R> implements FiberEngine<R> {
|
|
|
484
558
|
shutdown(): Promise<void>;
|
|
485
559
|
private scheduleWakeup;
|
|
486
560
|
private drainWakeups;
|
|
561
|
+
private enqueueFiber;
|
|
562
|
+
private enqueueFiberById;
|
|
563
|
+
private requestReadyDrain;
|
|
564
|
+
private drainReadyQueue;
|
|
487
565
|
private driveById;
|
|
566
|
+
private consumePendingResume;
|
|
488
567
|
private drive;
|
|
489
568
|
private scheduleAsync;
|
|
490
569
|
private scheduleHostAction;
|
|
570
|
+
private onTimerExpired;
|
|
491
571
|
private resumeWithExit;
|
|
492
572
|
private resumeWithValue;
|
|
493
573
|
private resumeWithError;
|
|
574
|
+
private schedulerTag;
|
|
575
|
+
private schedulerDropped;
|
|
494
576
|
private interruptById;
|
|
495
577
|
private interruptState;
|
|
496
578
|
private markSuspended;
|
|
@@ -510,14 +592,19 @@ declare const NoopHooks: RuntimeHooks;
|
|
|
510
592
|
type RuntimeOptions<R> = {
|
|
511
593
|
env: R;
|
|
512
594
|
scheduler?: Scheduler;
|
|
595
|
+
/** Logical caller/lane. When set, every fiber forked by this runtime is scheduled inside this lane. */
|
|
596
|
+
lane?: string;
|
|
597
|
+
/** Infer a caller lane from the top-level callsite when no explicit lane/parent lane exists. Defaults to true. */
|
|
598
|
+
inferLane?: boolean;
|
|
513
599
|
hooks?: RuntimeHooks;
|
|
514
600
|
/**
|
|
515
601
|
* Selects the fiber interpreter used by fork().
|
|
516
602
|
*
|
|
517
|
-
*
|
|
603
|
+
* Strict mode only accepts:
|
|
604
|
+
* - ts: TypeScript RuntimeFiber interpreter.
|
|
518
605
|
* - wasm: wasm-pack backed interpreter from wasm/pkg.
|
|
519
|
-
*
|
|
520
|
-
*
|
|
606
|
+
*
|
|
607
|
+
* There is no auto mode and no TS fallback when wasm is requested.
|
|
521
608
|
*/
|
|
522
609
|
engine?: RuntimeEngineMode;
|
|
523
610
|
/** Executor used by HostAction opcodes when running on the WASM engine. */
|
|
@@ -537,6 +624,8 @@ declare class Runtime<R> {
|
|
|
537
624
|
readonly forkPolicy: {
|
|
538
625
|
initChild(fiber: RuntimeFiber<any, any, any> & any, parent?: (RuntimeFiber<any, any, any> & any) | null, scopeId?: number): void;
|
|
539
626
|
};
|
|
627
|
+
readonly lane?: string;
|
|
628
|
+
readonly inferLane: boolean;
|
|
540
629
|
registry?: RuntimeRegistry;
|
|
541
630
|
constructor(args: RuntimeOptions<R>);
|
|
542
631
|
private makeFiberEngine;
|
|
@@ -544,6 +633,12 @@ declare class Runtime<R> {
|
|
|
544
633
|
hasActiveHooks(): boolean;
|
|
545
634
|
/** Deriva un runtime con env extendido (estilo provide/locally) */
|
|
546
635
|
provide<R2>(env: R2): Runtime<R & R2>;
|
|
636
|
+
/**
|
|
637
|
+
* Returns a derived runtime that schedules all work in a caller/lane.
|
|
638
|
+
* Brass does not need to know the caller implementation; it only sees this stable key.
|
|
639
|
+
*/
|
|
640
|
+
withLane(lane: string): Runtime<R>;
|
|
641
|
+
private resolveFiberLane;
|
|
547
642
|
emit(ev: RuntimeEvent): void;
|
|
548
643
|
/**
|
|
549
644
|
* ✅ CAMBIO: fork(effect, scopeId?) y pasa scopeId a forkPolicy
|
|
@@ -563,15 +658,65 @@ declare class Runtime<R> {
|
|
|
563
658
|
}
|
|
564
659
|
/** Create a runtime from `env` and fork the given effect. */
|
|
565
660
|
declare function fork<R, E, A>(effect: Async<R, E, A>, env?: R): Fiber<E, A>;
|
|
661
|
+
/** Create a runtime with a stable lane/caller key. */
|
|
662
|
+
declare function runtimeForCaller<R>(caller: string, env?: R): Runtime<R>;
|
|
663
|
+
/** Run an effect in a caller lane without exposing scheduler internals to the caller. */
|
|
664
|
+
declare function toPromiseByCaller<R, E, A>(caller: string, effect: Async<R, E, A>, env?: R): Promise<A>;
|
|
566
665
|
/** Run an effect with `env` and invoke `cb` with the final Exit. */
|
|
567
666
|
declare function unsafeRunAsync<R, E, A>(effect: Async<R, E, A>, env: R | undefined, cb: (exit: Exit<E, A>) => void): void;
|
|
568
667
|
/** Run an effect with `env` and return a Promise of its success value. */
|
|
569
668
|
declare function toPromise<R, E, A>(effect: Async<R, E, A>, env?: R): Promise<A>;
|
|
669
|
+
type AbortablePromiseOutcome = "success" | "failure" | "interrupt" | "timeout";
|
|
670
|
+
type AbortablePromiseFinish = {
|
|
671
|
+
readonly label: string;
|
|
672
|
+
readonly outcome: AbortablePromiseOutcome;
|
|
673
|
+
readonly durationMs: number;
|
|
674
|
+
readonly error?: unknown;
|
|
675
|
+
};
|
|
676
|
+
type AbortablePromiseOptions = {
|
|
677
|
+
/** Logical label used by diagnostics. Keep it low-cardinality: e.g. `http:GET:https://api.foo.com`. */
|
|
678
|
+
readonly label?: string;
|
|
679
|
+
/** Fails the effect after this budget and aborts the underlying signal. Disabled when omitted or <= 0. */
|
|
680
|
+
readonly timeoutMs?: number;
|
|
681
|
+
/** Custom reason passed to `onReject` when the timeout fires. */
|
|
682
|
+
readonly timeoutReason?: () => unknown;
|
|
683
|
+
readonly onStart?: (label: string) => void;
|
|
684
|
+
readonly onFinish?: (finish: AbortablePromiseFinish) => void;
|
|
685
|
+
};
|
|
686
|
+
type AbortablePromiseLabelStats = {
|
|
687
|
+
readonly label: string;
|
|
688
|
+
readonly active: number;
|
|
689
|
+
readonly started: number;
|
|
690
|
+
readonly succeeded: number;
|
|
691
|
+
readonly failed: number;
|
|
692
|
+
readonly interrupted: number;
|
|
693
|
+
readonly timedOut: number;
|
|
694
|
+
readonly lateSettlements: number;
|
|
695
|
+
};
|
|
696
|
+
type AbortablePromiseStats = {
|
|
697
|
+
readonly active: number;
|
|
698
|
+
readonly started: number;
|
|
699
|
+
readonly succeeded: number;
|
|
700
|
+
readonly failed: number;
|
|
701
|
+
readonly interrupted: number;
|
|
702
|
+
readonly timedOut: number;
|
|
703
|
+
readonly lateSettlements: number;
|
|
704
|
+
readonly byLabel: AbortablePromiseLabelStats[];
|
|
705
|
+
};
|
|
706
|
+
declare function abortablePromiseStats(): AbortablePromiseStats;
|
|
707
|
+
declare function resetAbortablePromiseStats(): void;
|
|
570
708
|
/**
|
|
571
709
|
* Create an Async from an abortable Promise.
|
|
710
|
+
*
|
|
711
|
+
* Improvements over the original helper:
|
|
712
|
+
* - optional timeout budget;
|
|
713
|
+
* - global active/late-settlement diagnostics;
|
|
714
|
+
* - explicit start/finish hooks for transport metrics;
|
|
715
|
+
* - cleanup on every completion path, so timers/listeners do not retain fibers.
|
|
716
|
+
*
|
|
572
717
|
* Type params are ordered as `<E, A, R = unknown>` to match call-sites.
|
|
573
718
|
*/
|
|
574
|
-
declare function fromPromiseAbortable<E, A, R = unknown>(make: (signal: AbortSignal, env: R) => Promise<A>, onReject: (u: unknown) => E): Async<R, E, A>;
|
|
719
|
+
declare function fromPromiseAbortable<E, A, R = unknown>(make: (signal: AbortSignal, env: R) => Promise<A>, onReject: (u: unknown) => E, options?: AbortablePromiseOptions): Async<R, E, A>;
|
|
575
720
|
declare function unsafeRunFoldWithEnv<R, E, A>(eff: Async<R, E, A>, env: R, onFailure: (cause: Cause<E>) => void, onSuccess: (value: A) => void): void;
|
|
576
721
|
|
|
577
722
|
type JSONValue = null | boolean | number | string | JSONValue[] | {
|
|
@@ -622,6 +767,7 @@ declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
|
|
|
622
767
|
fiberContext: FiberContext;
|
|
623
768
|
name?: string;
|
|
624
769
|
scopeId?: number;
|
|
770
|
+
lane?: string;
|
|
625
771
|
/**
|
|
626
772
|
* Cached closure for the scheduler callback — avoids creating a new
|
|
627
773
|
* closure on every `schedule()` call. The tag parameter used by the
|
|
@@ -629,11 +775,22 @@ declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
|
|
|
629
775
|
* so a single cached closure is sufficient.
|
|
630
776
|
*/
|
|
631
777
|
private readonly boundStep;
|
|
778
|
+
private _syncResolved;
|
|
779
|
+
private _syncExit;
|
|
780
|
+
private _asyncRegistered;
|
|
781
|
+
private _asyncDetach;
|
|
782
|
+
private readonly _asyncCb;
|
|
632
783
|
constructor(runtime: Runtime<R>, effect: Async<R, E, A>);
|
|
633
784
|
private get env();
|
|
634
785
|
private get scheduler();
|
|
635
786
|
private emit;
|
|
636
787
|
addFinalizer(f: (exit: Exit<E, A>) => void): void;
|
|
788
|
+
/**
|
|
789
|
+
* Internal finalizers used for suspend cancelers. They are detached as soon
|
|
790
|
+
* as the async operation completes, so completed HTTP/promises do not keep
|
|
791
|
+
* canceler closures alive until the fiber itself finishes.
|
|
792
|
+
*/
|
|
793
|
+
private addTransientFinalizer;
|
|
637
794
|
status(): FiberStatus;
|
|
638
795
|
join(cb: (exit: Exit<E, A>) => void): void;
|
|
639
796
|
interrupt(): void;
|
|
@@ -644,6 +801,19 @@ declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
|
|
|
644
801
|
private onFailure;
|
|
645
802
|
private budget;
|
|
646
803
|
private step;
|
|
804
|
+
/**
|
|
805
|
+
* Sync trampoline: processes FlatMap chains in a tight loop without the
|
|
806
|
+
* overhead of the general switch/case. Handles:
|
|
807
|
+
* - FlatMap(Async(sync), k) — the queue/stream hot path
|
|
808
|
+
* - FlatMap(Succeed(v), k) — pure value chains
|
|
809
|
+
* - FlatMap(Sync(f), k) — synchronous thunks
|
|
810
|
+
* - FlatMap(FlatMap(...), k) — left-associated chains (reassociates inline)
|
|
811
|
+
* - FlatMap(Fold(...), k) — pushes fold frame and continues
|
|
812
|
+
*
|
|
813
|
+
* Returns TRAMPOLINE.CONTINUE when it hits a node it can't handle,
|
|
814
|
+
* leaving this.current set to that node for the normal switch to process.
|
|
815
|
+
*/
|
|
816
|
+
private syncTrampoline;
|
|
647
817
|
}
|
|
648
818
|
declare function getCurrentFiber(): RuntimeFiber<any, any, any> | null;
|
|
649
819
|
/**
|
|
@@ -708,16 +878,16 @@ type Async<R, E, A> = {
|
|
|
708
878
|
readonly register: (env: R, cb: (exit: Exit<E, A>) => void) => void | (() => void);
|
|
709
879
|
} | {
|
|
710
880
|
readonly _tag: "FlatMap";
|
|
711
|
-
readonly first: Async<
|
|
712
|
-
readonly andThen: (a: any) => Async<
|
|
881
|
+
readonly first: Async<any, any, any>;
|
|
882
|
+
readonly andThen: (a: any) => Async<any, any, A>;
|
|
713
883
|
} | {
|
|
714
884
|
readonly _tag: "Fold";
|
|
715
|
-
readonly first: Async<
|
|
716
|
-
readonly onFailure: (e: any) => Async<
|
|
717
|
-
readonly onSuccess: (a: any) => Async<
|
|
885
|
+
readonly first: Async<any, any, any>;
|
|
886
|
+
readonly onFailure: (e: any) => Async<any, any, A>;
|
|
887
|
+
readonly onSuccess: (a: any) => Async<any, any, A>;
|
|
718
888
|
} | {
|
|
719
889
|
readonly _tag: "Fork";
|
|
720
|
-
readonly effect: Async<
|
|
890
|
+
readonly effect: Async<any, any, any>;
|
|
721
891
|
readonly scopeId?: number;
|
|
722
892
|
};
|
|
723
893
|
declare const Async: {
|
|
@@ -726,7 +896,7 @@ declare const Async: {
|
|
|
726
896
|
sync: <R, E, A>(thunk: (env: R) => A) => Async<R, E, A>;
|
|
727
897
|
async: <R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | (() => void)) => Async<R, E, A>;
|
|
728
898
|
};
|
|
729
|
-
declare function asyncFold<R, E, A, B>(fa: Async<R, E, A>, onFailure: (e: E) => Async<
|
|
899
|
+
declare function asyncFold<R, E, A, RFail, EFail, B, RSuccess, ESuccess, C>(fa: Async<R, E, A>, onFailure: (e: E) => Async<RFail, EFail, B>, onSuccess: (a: A) => Async<RSuccess, ESuccess, C>): Async<R & RFail & RSuccess, EFail | ESuccess, B | C>;
|
|
730
900
|
declare function asyncCatchAll<R, E, A, R2, E2, B>(fa: Async<R, E, A>, handler: (e: E) => Async<R2, E2, B>): Async<R & R2, E2, A | B>;
|
|
731
901
|
declare function asyncMapError<R, E, E2, A>(fa: Async<R, E, A>, f: (e: E) => E2): Async<R, E2, A>;
|
|
732
902
|
declare const unit: <R>() => Async<R, never, void>;
|
|
@@ -734,9 +904,10 @@ declare const asyncSucceed: <A>(value: A) => Async<unknown, never, A>;
|
|
|
734
904
|
declare const asyncFail: <E>(error: E) => Async<unknown, E, never>;
|
|
735
905
|
declare const asyncSync: <R, A>(thunk: (env: R) => A) => Async<R, unknown, A>;
|
|
736
906
|
declare const asyncTotal: <A>(thunk: () => A) => Async<unknown, unknown, A>;
|
|
737
|
-
declare const
|
|
907
|
+
declare const asyncEffect: <R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler) => Async<R, E, A>;
|
|
908
|
+
|
|
738
909
|
declare function asyncMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B): Async<R, E, B>;
|
|
739
|
-
declare function asyncFlatMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => Async<
|
|
910
|
+
declare function asyncFlatMap<R, E, A, R2, E2, B>(fa: Async<R, E, A>, f: (a: A) => Async<R2, E2, B>): Async<R & R2, E | E2, B>;
|
|
740
911
|
declare function acquireRelease<R, E, A>(acquire: Async<R, E, A>, release: (res: A, exit: Exit<E, any>) => Async<R, any, any>, scope: Scope<R>): Async<R, E, A>;
|
|
741
912
|
declare function asyncInterruptible<R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler): Async<R, E, A>;
|
|
742
913
|
type AsyncWithPromise<R, E, A> = Async<R, E, A> & {
|
|
@@ -789,9 +960,9 @@ declare const fail: <E>(error: E) => ZIO<unknown, E, never>;
|
|
|
789
960
|
declare const sync: <R, A>(thunk: (env: R) => A) => ZIO<R, unknown, A>;
|
|
790
961
|
declare const map: <R, E, A, B>(fa: ZIO<R, E, A>, f: (a: A) => B) => Async<R, E, B>;
|
|
791
962
|
declare const flatMap: <R, E, A, R2, E2, B>(fa: ZIO<R, E, A>, f: (a: A) => ZIO<R2, E2, B>) => ZIO<R & R2, E | E2, B>;
|
|
792
|
-
declare const mapError: <R, E, E2, A>(fa: ZIO<R, E, A>, f: (e: E) => E2) =>
|
|
963
|
+
declare const mapError: <R, E, E2, A>(fa: ZIO<R, E, A>, f: (e: E) => E2) => ZIO<R, E2, A>;
|
|
793
964
|
declare const catchAll: <R, E, A, R2, E2, B>(fa: ZIO<R, E, A>, handler: (e: E) => ZIO<R2, E2, B>) => ZIO<R & R2, E2, A | B>;
|
|
794
965
|
declare function orElseOptional<R, E, A, R2, A2>(fa: ZIO<R, Option<E>, A>, that: () => ZIO<R2, Option<E>, A2>): ZIO<R & R2, Option<E>, A | A2>;
|
|
795
966
|
declare const end: <E>() => ZIO<unknown, Option<E>, never>;
|
|
796
967
|
|
|
797
|
-
export { type
|
|
968
|
+
export { type Joiner as $, Async as A, type EngineKind as B, type CancelToken as C, type DbHostAction as D, Exit as E, type FiberEngine as F, type EngineSelection as G, type EngineSelectionMode as H, type FiberEngineKind as I, type FlatMapRef as J, type FoldFailureRef as K, type FoldSuccessRef as L, type HostAction as M, type NodeId as N, type Option as O, type HostActionKind as P, type HostActionResult as Q, RuntimeFiber as R, Scope as S, type HostExecutionContext as T, type HostExecutor as U, HostRegistry as V, type WasmEngineRuntime as W, type HostRegistryStats as X, type HttpHostAction as Y, type ZIO as Z, type Interrupted as _, type FiberEngineStats as a, sanitizeLaneKey as a$, type LaneStatsData as a0, type None as a1, NoopHooks as a2, ProgramBuilder as a3, type ProgramPatch as a4, PushStatus as a5, type QueueHostAction as a6, RingBuffer as a7, type RingBufferEngine as a8, type RingBufferStatsData as a9, asyncSucceed as aA, asyncSync as aB, asyncTotal as aC, catchAll as aD, end as aE, engineStats as aF, fail as aG, flatMap as aH, fork as aI, fromPromiseAbortable as aJ, getBenchmarkBudget as aK, getCurrentFiber as aL, globalScheduler as aM, inferCallerLaneFromStack as aN, laneTag as aO, linkAbortController as aP, makeBoundedRingBuffer as aQ, makeCancelToken as aR, map as aS, mapAsync as aT, mapError as aU, mapTryAsync as aV, none as aW, orElseOptional as aX, resetAbortablePromiseStats as aY, runtimeCapabilities as aZ, runtimeForCaller as a_, Runtime as aa, type RuntimeCapabilities as ab, type RuntimeEngineMode as ac, type RuntimeOptions as ad, type ScheduleResult as ae, Scheduler as af, type SchedulerEngine as ag, type SchedulerOptions as ah, type SchedulerStats as ai, type SchedulerStatsData as aj, type ScopeId as ak, type Some as al, type SyncRef as am, type Task as an, WasmFiberEngine as ao, type WasmFiberEngineOptions as ap, abortablePromiseStats as aq, acquireRelease as ar, asyncEffect as as, asyncCatchAll as at, asyncFail as au, asyncFlatMap as av, asyncFold as aw, asyncInterruptible as ax, asyncMap as ay, asyncMapError as az, type Fiber as b, selectedEngineStats as b0, setBenchmarkBudget as b1, some as b2, succeed as b3, sync as b4, toPromise as b5, toPromiseByCaller as b6, unit as b7, unsafeGetCurrentRuntime as b8, unsafeRunAsync as b9, unsafeRunFoldWithEnv as ba, withAsyncPromise as bb, withCurrentFiber as bc, withScope as bd, withScopeAsync as be, type FiberId as c, type FiberStatus as d, type RuntimeEvent as e, type WasmBridge as f, type OpcodeProgram as g, type FiberId$1 as h, type EngineEvent as i, type RefId as j, type OpcodeNode as k, type RingBufferOptions as l, type EngineStats as m, type AbortablePromiseFinish as n, type AbortablePromiseLabelStats as o, type AbortablePromiseOptions as p, type AbortablePromiseOutcome as q, type AbortablePromiseStats as r, type AsyncRegisterRef as s, type AsyncWithPromise as t, type RingLike as u, type Canceler as v, Cause as w, type CustomHostAction as x, type DecodeRef as y, DefaultHostExecutor as z };
|