brass-runtime 1.18.0 → 1.18.2

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.
Files changed (84) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/agent/cli/main.cjs +31 -31
  3. package/dist/agent/cli/main.js +3 -3
  4. package/dist/agent/cli/main.mjs +3 -3
  5. package/dist/agent/index.cjs +4 -4
  6. package/dist/agent/index.d.ts +1 -1
  7. package/dist/agent/index.js +3 -3
  8. package/dist/agent/index.mjs +3 -3
  9. package/dist/{chunk-PSEU65ND.js → chunk-2R3RVNS2.js} +6 -6
  10. package/dist/{chunk-ITZQ526U.mjs → chunk-3NKXUX4T.mjs} +2 -2
  11. package/dist/{chunk-JH4GI3DW.js → chunk-4PKBNG2H.js} +38 -18
  12. package/dist/{chunk-Z3PSSXP3.mjs → chunk-5RVHSBJ6.mjs} +292 -36
  13. package/dist/{chunk-QZ6QFJNM.mjs → chunk-5UBJT4RW.mjs} +4 -4
  14. package/dist/{chunk-7TXQJFZX.cjs → chunk-6STX4PS3.cjs} +13 -13
  15. package/dist/{chunk-VIFA4DPN.cjs → chunk-7FZUTJM3.cjs} +508 -252
  16. package/dist/{chunk-4YQHPIWJ.js → chunk-A6EG5WRL.js} +3 -3
  17. package/dist/{chunk-XSAHV5HQ.js → chunk-APQBU7TM.js} +264 -133
  18. package/dist/{chunk-RREBJX2S.mjs → chunk-AQQQFNYD.mjs} +38 -18
  19. package/dist/{chunk-AADFFVYS.js → chunk-B2VXVNIS.js} +1 -1
  20. package/dist/{chunk-R6WDSZA6.mjs → chunk-BLXBZ6RE.mjs} +1 -1
  21. package/dist/{chunk-ITG6I7ZS.js → chunk-C3CWI42G.js} +1 -1
  22. package/dist/{chunk-LXBU5E77.cjs → chunk-DV644N7P.cjs} +85 -85
  23. package/dist/{chunk-G5JTCFMI.mjs → chunk-EKLEDIVJ.mjs} +2 -2
  24. package/dist/{chunk-IBRHSH5H.js → chunk-EXBGIC66.js} +1 -1
  25. package/dist/{chunk-W6WR37HN.js → chunk-FC5N5QHJ.js} +2 -2
  26. package/dist/{chunk-6MLAZPBL.mjs → chunk-FNWOH2T2.js} +18 -6
  27. package/dist/{chunk-AJMKZXRB.cjs → chunk-FYWWU3Z7.cjs} +2 -2
  28. package/dist/{chunk-IFRBVMWJ.cjs → chunk-GOEO763K.cjs} +21 -21
  29. package/dist/{chunk-S4HHFUYP.js → chunk-GXOIUBKE.js} +2 -2
  30. package/dist/{chunk-BG5RNEA2.js → chunk-H4ZRUQZL.js} +4 -4
  31. package/dist/{chunk-OI4ESUMC.mjs → chunk-HW2CLRJ3.mjs} +6 -6
  32. package/dist/{chunk-3PHU7FWS.js → chunk-JWFOWPMB.js} +163 -155
  33. package/dist/{chunk-OT2TESZU.mjs → chunk-KAPZHDO4.mjs} +1 -1
  34. package/dist/{chunk-ELLF55ER.mjs → chunk-KDXNWGPB.mjs} +1 -1
  35. package/dist/{chunk-UUMKZJRJ.cjs → chunk-KPOL2YEO.cjs} +18 -6
  36. package/dist/{chunk-2SLT3X6G.cjs → chunk-MA74OYCI.cjs} +6 -6
  37. package/dist/{chunk-2QNREG6K.mjs → chunk-MUMBUXU6.mjs} +264 -133
  38. package/dist/{chunk-YTX2JYYP.cjs → chunk-NQW3YUFN.cjs} +18 -18
  39. package/dist/{chunk-3PFZGP23.cjs → chunk-OO7BGCC3.cjs} +54 -34
  40. package/dist/{chunk-QCOLAHU3.mjs → chunk-OX6MF7SZ.mjs} +163 -155
  41. package/dist/{chunk-KHACHFBQ.cjs → chunk-QBVS3UYN.cjs} +245 -237
  42. package/dist/{chunk-H5GYX7RZ.js → chunk-RZGB3DXR.js} +292 -36
  43. package/dist/{chunk-KRYP6CAE.mjs → chunk-URVS2OE2.mjs} +3 -3
  44. package/dist/{chunk-HCJ4S3YB.js → chunk-UZQ3BB6W.mjs} +18 -6
  45. package/dist/{chunk-N6QNSTWD.cjs → chunk-YQWZ7FZX.cjs} +5 -5
  46. package/dist/{chunk-5XADBMSU.cjs → chunk-Z2YIDHRI.cjs} +5 -5
  47. package/dist/{chunk-SSQJKDN3.cjs → chunk-ZDZNV6NA.cjs} +286 -155
  48. package/dist/core/index.cjs +14 -8
  49. package/dist/core/index.d.ts +6 -6
  50. package/dist/core/index.js +13 -7
  51. package/dist/core/index.mjs +13 -7
  52. package/dist/{defaultClient-DhpCQW9m.d.ts → defaultClient-Cid0JoUR.d.ts} +29 -4
  53. package/dist/{effect-CtUDl5M5.d.ts → effect-DnGUuhw6.d.ts} +22 -1
  54. package/dist/http/index.cjs +58 -54
  55. package/dist/http/index.d.ts +8 -8
  56. package/dist/http/index.js +11 -7
  57. package/dist/http/index.mjs +11 -7
  58. package/dist/http/testing.cjs +9 -9
  59. package/dist/http/testing.d.ts +4 -4
  60. package/dist/http/testing.js +5 -5
  61. package/dist/http/testing.mjs +5 -5
  62. package/dist/index.cjs +92 -86
  63. package/dist/index.d.ts +7 -7
  64. package/dist/index.js +14 -8
  65. package/dist/index.mjs +14 -8
  66. package/dist/{layer-BalPI6cN.d.ts → layer-D2LFcBVx.d.ts} +1 -1
  67. package/dist/observability/index.cjs +10 -10
  68. package/dist/observability/index.d.ts +7 -7
  69. package/dist/observability/index.js +9 -9
  70. package/dist/observability/index.mjs +9 -9
  71. package/dist/perf/cli.cjs +26 -26
  72. package/dist/perf/cli.js +11 -11
  73. package/dist/perf/cli.mjs +11 -11
  74. package/dist/perf/index.cjs +13 -13
  75. package/dist/perf/index.js +11 -11
  76. package/dist/perf/index.mjs +11 -11
  77. package/dist/schema/index.cjs +2 -2
  78. package/dist/schema/index.js +1 -1
  79. package/dist/schema/index.mjs +1 -1
  80. package/dist/{server-C1zVmqE6.d.ts → server-Bf1zNYZk.d.ts} +4 -4
  81. package/dist/{stream-Bb4FTejt.d.ts → stream-I7bkvF7a.d.ts} +1 -1
  82. package/dist/{tracer-DzfuE6um.d.ts → tracer-DF83nLn6.d.ts} +2 -2
  83. package/dist/{tracing-BABA5arE.d.ts → tracing-CWV4gT0u.d.ts} +1 -1
  84. package/package.json +3 -2
@@ -10,7 +10,7 @@ var _chunkMVGUEJ5Zcjs = require('./chunk-MVGUEJ5Z.cjs');
10
10
 
11
11
 
12
12
 
13
- var _chunkUUMKZJRJcjs = require('./chunk-UUMKZJRJ.cjs');
13
+ var _chunkKPOL2YEOcjs = require('./chunk-KPOL2YEO.cjs');
14
14
 
15
15
  // src/core/runtime/ringBuffer.ts
16
16
  var PushStatus = /* @__PURE__ */ ((PushStatus3) => {
@@ -2827,11 +2827,11 @@ function normalizeRuntimeEngineMode(value) {
2827
2827
  function unreachableEngine(value) {
2828
2828
  throw new Error(`brass-runtime unsupported engine '${String(value)}'`);
2829
2829
  }
2830
- var runtimeOptionsSchema = _chunkUUMKZJRJcjs.Schema.object({
2831
- env: _chunkUUMKZJRJcjs.Schema.any(),
2832
- lane: _chunkUUMKZJRJcjs.Schema.string({ minLength: 1 }).optional(),
2833
- inferLane: _chunkUUMKZJRJcjs.Schema.boolean().optional(),
2834
- engine: _chunkUUMKZJRJcjs.Schema.enum(["ts", "wasm"]).optional()
2830
+ var runtimeOptionsSchema = _chunkKPOL2YEOcjs.Schema.object({
2831
+ env: _chunkKPOL2YEOcjs.Schema.any(),
2832
+ lane: _chunkKPOL2YEOcjs.Schema.string({ minLength: 1 }).optional(),
2833
+ inferLane: _chunkKPOL2YEOcjs.Schema.boolean().optional(),
2834
+ engine: _chunkKPOL2YEOcjs.Schema.enum(["ts", "wasm"]).optional()
2835
2835
  }, { unknownKeys: "passthrough" });
2836
2836
  var Runtime = class _Runtime {
2837
2837
 
@@ -2848,7 +2848,7 @@ var Runtime = class _Runtime {
2848
2848
  // opcional: registry para observabilidad
2849
2849
 
2850
2850
  constructor(args) {
2851
- _chunkUUMKZJRJcjs.parseConfig.call(void 0, "RuntimeOptions", runtimeOptionsSchema, args);
2851
+ _chunkKPOL2YEOcjs.parseConfig.call(void 0, "RuntimeOptions", runtimeOptionsSchema, args);
2852
2852
  this.env = args.env;
2853
2853
  this.scheduler = _nullishCoalesce(args.scheduler, () => ( globalScheduler));
2854
2854
  this.lane = args.lane;
@@ -2950,31 +2950,43 @@ var Runtime = class _Runtime {
2950
2950
  const fiber = this.fork(effect);
2951
2951
  fiber.join(cb);
2952
2952
  }
2953
+ static exitToError(exit) {
2954
+ if (exit._tag === "Success") return void 0;
2955
+ const failure = _chunkMVGUEJ5Zcjs.Cause.firstFailure(exit.cause);
2956
+ if (failure._tag === "Some") return failure.value;
2957
+ const defect = _chunkMVGUEJ5Zcjs.Cause.firstDefect(exit.cause);
2958
+ if (defect._tag === "Some") {
2959
+ return defect.value instanceof Error ? defect.value : new Error(String(defect.value));
2960
+ }
2961
+ if (_chunkMVGUEJ5Zcjs.Cause.containsInterrupt(exit.cause)) return new Error("Interrupted");
2962
+ return _chunkMVGUEJ5Zcjs.Cause.toError(exit.cause);
2963
+ }
2953
2964
  toPromise(effect) {
2965
+ let syncExit;
2966
+ let promiseResolve;
2967
+ let promiseReject;
2968
+ const complete = (exit) => {
2969
+ if (promiseResolve) {
2970
+ if (exit._tag === "Success") promiseResolve(exit.value);
2971
+ else promiseReject(_Runtime.exitToError(exit));
2972
+ } else {
2973
+ syncExit = exit;
2974
+ }
2975
+ };
2976
+ if (this.tryRunNativeTopLevel(effect, complete)) {
2977
+ if (syncExit) {
2978
+ return syncExit._tag === "Success" ? Promise.resolve(syncExit.value) : Promise.reject(_Runtime.exitToError(syncExit));
2979
+ }
2980
+ return new Promise((resolve, reject) => {
2981
+ promiseResolve = resolve;
2982
+ promiseReject = reject;
2983
+ });
2984
+ }
2954
2985
  return new Promise((resolve, reject) => {
2955
- const complete = (exit) => {
2956
- if (exit._tag === "Success") {
2957
- resolve(exit.value);
2958
- return;
2959
- }
2960
- const failure = _chunkMVGUEJ5Zcjs.Cause.firstFailure(exit.cause);
2961
- if (failure._tag === "Some") reject(failure.value);
2962
- else {
2963
- const defect = _chunkMVGUEJ5Zcjs.Cause.firstDefect(exit.cause);
2964
- if (defect._tag === "Some") {
2965
- reject(defect.value instanceof Error ? defect.value : new Error(String(defect.value)));
2966
- } else if (_chunkMVGUEJ5Zcjs.Cause.containsInterrupt(exit.cause)) {
2967
- reject(new Error("Interrupted"));
2968
- } else {
2969
- reject(_chunkMVGUEJ5Zcjs.Cause.toError(exit.cause));
2970
- }
2971
- }
2972
- };
2973
- if (this.tryRunNativeTopLevel(effect, complete)) return;
2986
+ promiseResolve = resolve;
2987
+ promiseReject = reject;
2974
2988
  const fiber = this.fork(effect);
2975
- fiber.join((exit) => {
2976
- complete(exit);
2977
- });
2989
+ fiber.join(complete);
2978
2990
  });
2979
2991
  }
2980
2992
  tryRunNativeTopLevel(effect, cb) {
@@ -3017,32 +3029,43 @@ var NativeTopLevelRunner = (_class16 = class {
3017
3029
  constructor(runtime, effect, cb) {;_class16.prototype.__init99.call(this);_class16.prototype.__init100.call(this);_class16.prototype.__init101.call(this);_class16.prototype.__init102.call(this);
3018
3030
  this.runtime = runtime;
3019
3031
  this.current = effect;
3020
- this.joiners.push(cb);
3021
- this.frame = {
3022
- id: 0,
3023
- runtime,
3024
- name: "native-fast-path",
3025
- fiberContext: { trace: null },
3026
- lane: runtime.lane,
3027
- status: () => this.result ? "Done" : "Running",
3028
- join: (joiner) => {
3029
- if (this.result) joiner(this.result);
3030
- else this.joiners.push(joiner);
3031
- },
3032
- interrupt: () => void 0,
3033
- addFinalizer: (finalizer) => {
3034
- this.finalizers.push(finalizer);
3035
- }
3036
- };
3032
+ this.firstJoiner = cb;
3037
3033
  }
3038
3034
 
3039
3035
 
3040
- __init99() {this.stack = []}
3041
- __init100() {this.joiners = []}
3042
- __init101() {this.finalizers = []}
3036
+ // Lazy-allocated most requests don't need these
3043
3037
 
3044
- __init102() {this.yielded = false}
3045
3038
 
3039
+
3040
+
3041
+ __init99() {this.yielded = false}
3042
+
3043
+ // Frame is now the runner itself — avoids allocating a separate frame object
3044
+ // with 4 closures per request. We implement the Fiber-like interface inline.
3045
+ __init100() {this.id = 0}
3046
+ __init101() {this.name = "native-fast-path"}
3047
+ __init102() {this.fiberContext = { trace: null }}
3048
+ get lane() {
3049
+ return this.runtime.lane;
3050
+ }
3051
+ // Fiber-like interface methods (used by frame consumers)
3052
+ status() {
3053
+ return this.result ? "Done" : "Running";
3054
+ }
3055
+ join(joiner) {
3056
+ if (this.result) {
3057
+ joiner(this.result);
3058
+ return;
3059
+ }
3060
+ if (!this.joiners) this.joiners = [];
3061
+ this.joiners.push(joiner);
3062
+ }
3063
+ interrupt() {
3064
+ }
3065
+ addFinalizer(finalizer) {
3066
+ if (!this.finalizers) this.finalizers = [];
3067
+ this.finalizers.push(finalizer);
3068
+ }
3046
3069
  start() {
3047
3070
  this.runLoop();
3048
3071
  }
@@ -3067,10 +3090,12 @@ var NativeTopLevelRunner = (_class16 = class {
3067
3090
  }
3068
3091
  break;
3069
3092
  case "FlatMap":
3093
+ if (!this.stack) this.stack = [];
3070
3094
  this.stack.push({ _tag: "SuccessCont", k: current.andThen });
3071
3095
  this.current = current.first;
3072
3096
  break;
3073
3097
  case "Fold":
3098
+ if (!this.stack) this.stack = [];
3074
3099
  this.stack.push({
3075
3100
  _tag: "FoldCont",
3076
3101
  onFailure: current.onFailure,
@@ -3085,10 +3110,12 @@ var NativeTopLevelRunner = (_class16 = class {
3085
3110
  this.onSuccess(this.runtime.fork(current.effect, current.scopeId));
3086
3111
  break;
3087
3112
  case "Interruptibility":
3113
+ if (!this.stack) this.stack = [];
3088
3114
  this.stack.push({ _tag: "InterruptibilityCont" });
3089
3115
  this.current = current.effect;
3090
3116
  break;
3091
3117
  case "InterruptibilityMask":
3118
+ if (!this.stack) this.stack = [];
3092
3119
  this.stack.push({ _tag: "InterruptibilityCont" });
3093
3120
  try {
3094
3121
  this.current = current.body((effect) => ({
@@ -3101,6 +3128,7 @@ var NativeTopLevelRunner = (_class16 = class {
3101
3128
  }
3102
3129
  break;
3103
3130
  case "InterruptibilityRestore":
3131
+ if (!this.stack) this.stack = [];
3104
3132
  this.stack.push({ _tag: "InterruptibilityCont" });
3105
3133
  this.current = current.effect;
3106
3134
  break;
@@ -3109,6 +3137,7 @@ var NativeTopLevelRunner = (_class16 = class {
3109
3137
  const hadValue = refs.has(current.refId);
3110
3138
  const previousValue = refs.get(current.refId);
3111
3139
  refs.set(current.refId, current.value);
3140
+ if (!this.stack) this.stack = [];
3112
3141
  this.stack.push({
3113
3142
  _tag: "FiberRefCont",
3114
3143
  refId: current.refId,
@@ -3167,7 +3196,7 @@ var NativeTopLevelRunner = (_class16 = class {
3167
3196
  onSuccess(value) {
3168
3197
  let currentValue = value;
3169
3198
  while (true) {
3170
- const frame = this.stack.pop();
3199
+ const frame = this.stack ? this.stack.pop() : void 0;
3171
3200
  if (!frame) {
3172
3201
  this.notify(_chunkMVGUEJ5Zcjs.Exit.succeed(currentValue));
3173
3202
  return;
@@ -3195,7 +3224,7 @@ var NativeTopLevelRunner = (_class16 = class {
3195
3224
  }
3196
3225
  onCause(cause) {
3197
3226
  let currentCause = cause;
3198
- while (this.stack.length > 0) {
3227
+ while (this.stack && this.stack.length > 0) {
3199
3228
  const frame = this.stack.pop();
3200
3229
  if (frame._tag === "InterruptibilityCont") continue;
3201
3230
  if (frame._tag === "FiberRefCont") {
@@ -3220,13 +3249,17 @@ var NativeTopLevelRunner = (_class16 = class {
3220
3249
  notify(exit) {
3221
3250
  if (this.result) return;
3222
3251
  this.result = exit;
3223
- this.runFinalizers(exit);
3224
- for (const joiner of this.joiners) joiner(exit);
3225
- this.joiners.length = 0;
3252
+ if (this.finalizers) this.runFinalizers(exit);
3253
+ this.firstJoiner(exit);
3254
+ if (this.joiners) {
3255
+ for (const joiner of this.joiners) joiner(exit);
3256
+ this.joiners.length = 0;
3257
+ }
3226
3258
  }
3227
3259
  runFinalizers(exit) {
3228
- while (this.finalizers.length > 0) {
3229
- const finalizer = this.finalizers.pop();
3260
+ const finalizers = this.finalizers;
3261
+ while (finalizers.length > 0) {
3262
+ const finalizer = finalizers.pop();
3230
3263
  try {
3231
3264
  const result = finalizer(exit);
3232
3265
  if (result && typeof result === "object" && "_tag" in result) {
@@ -3237,8 +3270,8 @@ var NativeTopLevelRunner = (_class16 = class {
3237
3270
  }
3238
3271
  }
3239
3272
  fiberRefs() {
3240
- this.frame.fiberContext.fiberRefs ??= /* @__PURE__ */ new Map();
3241
- return this.frame.fiberContext.fiberRefs;
3273
+ this.fiberContext.fiberRefs ??= /* @__PURE__ */ new Map();
3274
+ return this.fiberContext.fiberRefs;
3242
3275
  }
3243
3276
  restoreFiberRef(frame) {
3244
3277
  const refs = this.fiberRefs();
@@ -3246,7 +3279,7 @@ var NativeTopLevelRunner = (_class16 = class {
3246
3279
  else refs.delete(frame.refId);
3247
3280
  }
3248
3281
  withFrame(body) {
3249
- return withCurrentFiber(this.frame, body);
3282
+ return withCurrentFiber(this, body);
3250
3283
  }
3251
3284
  }, _class16);
3252
3285
  function fork(effect, env) {
@@ -3274,6 +3307,12 @@ var abortablePromiseTotals = {
3274
3307
  lateSettlements: 0
3275
3308
  };
3276
3309
  var abortablePromiseLabels = /* @__PURE__ */ new Map();
3310
+ var perLabelTrackingEnabled = false;
3311
+ function setAbortablePromisePerLabelTracking(enabled) {
3312
+ const previous = perLabelTrackingEnabled;
3313
+ perLabelTrackingEnabled = enabled;
3314
+ return previous;
3315
+ }
3277
3316
  var getAbortablePromiseLabelStats = (label) => {
3278
3317
  const existing = abortablePromiseLabels.get(label);
3279
3318
  if (existing) return existing;
@@ -3291,44 +3330,60 @@ var getAbortablePromiseLabelStats = (label) => {
3291
3330
  return created;
3292
3331
  };
3293
3332
  var recordAbortablePromiseStart = (label) => {
3294
- const byLabel = getAbortablePromiseLabelStats(label);
3295
3333
  abortablePromiseTotals.active++;
3296
3334
  abortablePromiseTotals.started++;
3297
- byLabel.active++;
3298
- byLabel.started++;
3335
+ if (perLabelTrackingEnabled) {
3336
+ const byLabel = getAbortablePromiseLabelStats(label);
3337
+ byLabel.active++;
3338
+ byLabel.started++;
3339
+ }
3299
3340
  };
3300
3341
  var recordAbortablePromiseFinish = (label, outcome) => {
3301
- const byLabel = getAbortablePromiseLabelStats(label);
3302
3342
  if (abortablePromiseTotals.active > 0) abortablePromiseTotals.active--;
3303
- if (byLabel.active > 0) byLabel.active--;
3304
3343
  switch (outcome) {
3305
3344
  case "success":
3306
3345
  abortablePromiseTotals.succeeded++;
3307
- byLabel.succeeded++;
3308
- return;
3346
+ break;
3309
3347
  case "failure":
3310
3348
  abortablePromiseTotals.failed++;
3311
- byLabel.failed++;
3312
- return;
3349
+ break;
3313
3350
  case "interrupt":
3314
3351
  abortablePromiseTotals.interrupted++;
3315
- byLabel.interrupted++;
3316
- return;
3352
+ break;
3317
3353
  case "timeout":
3318
3354
  abortablePromiseTotals.timedOut++;
3319
- byLabel.timedOut++;
3320
- return;
3355
+ break;
3356
+ }
3357
+ if (perLabelTrackingEnabled) {
3358
+ const byLabel = getAbortablePromiseLabelStats(label);
3359
+ if (byLabel.active > 0) byLabel.active--;
3360
+ switch (outcome) {
3361
+ case "success":
3362
+ byLabel.succeeded++;
3363
+ return;
3364
+ case "failure":
3365
+ byLabel.failed++;
3366
+ return;
3367
+ case "interrupt":
3368
+ byLabel.interrupted++;
3369
+ return;
3370
+ case "timeout":
3371
+ byLabel.timedOut++;
3372
+ return;
3373
+ }
3321
3374
  }
3322
3375
  };
3323
3376
  var recordAbortablePromiseLateSettlement = (label) => {
3324
- const byLabel = getAbortablePromiseLabelStats(label);
3325
3377
  abortablePromiseTotals.lateSettlements++;
3326
- byLabel.lateSettlements++;
3378
+ if (perLabelTrackingEnabled) {
3379
+ const byLabel = getAbortablePromiseLabelStats(label);
3380
+ byLabel.lateSettlements++;
3381
+ }
3327
3382
  };
3328
3383
  function abortablePromiseStats() {
3329
3384
  return {
3330
3385
  ...abortablePromiseTotals,
3331
- byLabel: Array.from(abortablePromiseLabels.values()).map((x) => ({ ...x })).sort((a, b) => b.active - a.active || b.started - a.started || a.label.localeCompare(b.label))
3386
+ byLabel: perLabelTrackingEnabled ? Array.from(abortablePromiseLabels.values()).map((x) => ({ ...x })).sort((a, b) => b.active - a.active || b.started - a.started || a.label.localeCompare(b.label)) : []
3332
3387
  };
3333
3388
  }
3334
3389
  function resetAbortablePromiseStats() {
@@ -3350,76 +3405,149 @@ var makeTimeoutReason = (timeoutMs, label) => ({
3350
3405
  timeoutMs,
3351
3406
  message: `Abortable promise '${label}' timed out after ${timeoutMs}ms`
3352
3407
  });
3408
+ function registerWithTimeout(make, onReject, options, env, cb, timeoutMs) {
3409
+ const controller = new AbortController();
3410
+ const label = normalizeAbortablePromiseLabel(options.label);
3411
+ const startedAt = performance.now();
3412
+ let done = false;
3413
+ let cleanup;
3414
+ const hasHooks = options.onStart !== void 0 || options.onFinish !== void 0;
3415
+ const finish = hasHooks ? (outcome, exit, error) => {
3416
+ if (done) return;
3417
+ done = true;
3418
+ cleanup();
3419
+ recordAbortablePromiseFinish(label, outcome);
3420
+ _optionalChain([options, 'access', _189 => _189.onFinish, 'optionalCall', _190 => _190({
3421
+ label,
3422
+ outcome,
3423
+ durationMs: Math.round(performance.now() - startedAt),
3424
+ error
3425
+ })]);
3426
+ cb(exit);
3427
+ } : (outcome, exit, _error) => {
3428
+ if (done) return;
3429
+ done = true;
3430
+ cleanup();
3431
+ recordAbortablePromiseFinish(label, outcome);
3432
+ cb(exit);
3433
+ };
3434
+ recordAbortablePromiseStart(label);
3435
+ if (hasHooks) _optionalChain([options, 'access', _191 => _191.onStart, 'optionalCall', _192 => _192(label)]);
3436
+ const onTimeout = () => {
3437
+ const reason = _nullishCoalesce(_optionalChain([options, 'access', _193 => _193.timeoutReason, 'optionalCall', _194 => _194()]), () => ( makeTimeoutReason(timeoutMs, label)));
3438
+ try {
3439
+ controller.abort(reason);
3440
+ } catch (e10) {
3441
+ controller.abort();
3442
+ }
3443
+ finish("timeout", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(reason))), reason);
3444
+ };
3445
+ if (options.timerWheel) {
3446
+ const handle = options.timerWheel.schedule(timeoutMs, onTimeout);
3447
+ cleanup = () => {
3448
+ handle.cancel();
3449
+ };
3450
+ } else {
3451
+ let timeoutHandle = setTimeout(onTimeout, timeoutMs);
3452
+ cleanup = () => {
3453
+ if (timeoutHandle !== void 0) {
3454
+ clearTimeout(timeoutHandle);
3455
+ timeoutHandle = void 0;
3456
+ }
3457
+ };
3458
+ }
3459
+ let promise;
3460
+ try {
3461
+ promise = make(controller.signal, env);
3462
+ } catch (err) {
3463
+ finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
3464
+ return () => void 0;
3465
+ }
3466
+ promise.then((value) => {
3467
+ if (done) {
3468
+ recordAbortablePromiseLateSettlement(label);
3469
+ return;
3470
+ }
3471
+ finish("success", _chunkMVGUEJ5Zcjs.Exit.succeed(value));
3472
+ }).catch((err) => {
3473
+ if (done) {
3474
+ recordAbortablePromiseLateSettlement(label);
3475
+ return;
3476
+ }
3477
+ finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
3478
+ });
3479
+ return () => {
3480
+ if (done) return;
3481
+ try {
3482
+ controller.abort();
3483
+ } catch (e11) {
3484
+ }
3485
+ finish("interrupt", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt()));
3486
+ };
3487
+ }
3488
+ function registerWithoutTimeout(make, onReject, options, env, cb) {
3489
+ const controller = new AbortController();
3490
+ const label = normalizeAbortablePromiseLabel(options.label);
3491
+ const startedAt = performance.now();
3492
+ let done = false;
3493
+ const hasHooks = options.onStart !== void 0 || options.onFinish !== void 0;
3494
+ const finish = hasHooks ? (outcome, exit, error) => {
3495
+ if (done) return;
3496
+ done = true;
3497
+ recordAbortablePromiseFinish(label, outcome);
3498
+ _optionalChain([options, 'access', _195 => _195.onFinish, 'optionalCall', _196 => _196({
3499
+ label,
3500
+ outcome,
3501
+ durationMs: Math.round(performance.now() - startedAt),
3502
+ error
3503
+ })]);
3504
+ cb(exit);
3505
+ } : (outcome, exit, _error) => {
3506
+ if (done) return;
3507
+ done = true;
3508
+ recordAbortablePromiseFinish(label, outcome);
3509
+ cb(exit);
3510
+ };
3511
+ recordAbortablePromiseStart(label);
3512
+ if (hasHooks) _optionalChain([options, 'access', _197 => _197.onStart, 'optionalCall', _198 => _198(label)]);
3513
+ let promise;
3514
+ try {
3515
+ promise = make(controller.signal, env);
3516
+ } catch (err) {
3517
+ finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
3518
+ return () => void 0;
3519
+ }
3520
+ promise.then((value) => {
3521
+ if (done) {
3522
+ recordAbortablePromiseLateSettlement(label);
3523
+ return;
3524
+ }
3525
+ finish("success", _chunkMVGUEJ5Zcjs.Exit.succeed(value));
3526
+ }).catch((err) => {
3527
+ if (done) {
3528
+ recordAbortablePromiseLateSettlement(label);
3529
+ return;
3530
+ }
3531
+ finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
3532
+ });
3533
+ return () => {
3534
+ if (done) return;
3535
+ try {
3536
+ controller.abort();
3537
+ } catch (e12) {
3538
+ }
3539
+ finish("interrupt", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt()));
3540
+ };
3541
+ }
3353
3542
  function fromPromiseAbortable(make, onReject, options = {}) {
3354
3543
  return {
3355
3544
  _tag: "Async",
3356
3545
  register: (env, cb) => {
3357
- const controller = new AbortController();
3358
- const label = normalizeAbortablePromiseLabel(options.label);
3359
3546
  const timeoutMs = options.timeoutMs !== void 0 && Number.isFinite(options.timeoutMs) ? Math.max(0, Math.floor(options.timeoutMs)) : void 0;
3360
- const startedAt = performance.now();
3361
- let done = false;
3362
- let timeoutHandle;
3363
- const cleanup = () => {
3364
- if (timeoutHandle !== void 0) {
3365
- clearTimeout(timeoutHandle);
3366
- timeoutHandle = void 0;
3367
- }
3368
- };
3369
- const finish = (outcome, exit, error) => {
3370
- if (done) return;
3371
- done = true;
3372
- cleanup();
3373
- recordAbortablePromiseFinish(label, outcome);
3374
- _optionalChain([options, 'access', _189 => _189.onFinish, 'optionalCall', _190 => _190({
3375
- label,
3376
- outcome,
3377
- durationMs: Math.round(performance.now() - startedAt),
3378
- error
3379
- })]);
3380
- cb(exit);
3381
- };
3382
- recordAbortablePromiseStart(label);
3383
- _optionalChain([options, 'access', _191 => _191.onStart, 'optionalCall', _192 => _192(label)]);
3384
3547
  if (timeoutMs !== void 0 && timeoutMs > 0) {
3385
- timeoutHandle = setTimeout(() => {
3386
- const reason = _nullishCoalesce(_optionalChain([options, 'access', _193 => _193.timeoutReason, 'optionalCall', _194 => _194()]), () => ( makeTimeoutReason(timeoutMs, label)));
3387
- try {
3388
- controller.abort(reason);
3389
- } catch (e10) {
3390
- controller.abort();
3391
- }
3392
- finish("timeout", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(reason))), reason);
3393
- }, timeoutMs);
3394
- }
3395
- let promise;
3396
- try {
3397
- promise = make(controller.signal, env);
3398
- } catch (err) {
3399
- finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
3400
- return () => void 0;
3548
+ return registerWithTimeout(make, onReject, options, env, cb, timeoutMs);
3401
3549
  }
3402
- promise.then((value) => {
3403
- if (done) {
3404
- recordAbortablePromiseLateSettlement(label);
3405
- return;
3406
- }
3407
- finish("success", _chunkMVGUEJ5Zcjs.Exit.succeed(value));
3408
- }).catch((err) => {
3409
- if (done) {
3410
- recordAbortablePromiseLateSettlement(label);
3411
- return;
3412
- }
3413
- finish("failure", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.fail(onReject(err))), err);
3414
- });
3415
- return () => {
3416
- if (done) return;
3417
- try {
3418
- controller.abort();
3419
- } catch (e11) {
3420
- }
3421
- finish("interrupt", _chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt()));
3422
- };
3550
+ return registerWithoutTimeout(make, onReject, options, env, cb);
3423
3551
  }
3424
3552
  };
3425
3553
  }
@@ -3507,7 +3635,7 @@ var RuntimeFiber = (_class17 = class {
3507
3635
  return;
3508
3636
  }
3509
3637
  this._syncResolved = true;
3510
- _optionalChain([this, 'access', _195 => _195._asyncDetach, 'optionalCall', _196 => _196()]);
3638
+ _optionalChain([this, 'access', _199 => _199._asyncDetach, 'optionalCall', _200 => _200()]);
3511
3639
  this._asyncDetach = void 0;
3512
3640
  if (exit._tag === "Success") {
3513
3641
  this.current = _chunkMVGUEJ5Zcjs.Async.succeed(exit.value);
@@ -3549,12 +3677,12 @@ var RuntimeFiber = (_class17 = class {
3549
3677
  this.runtime.hooks.emit(ev, {
3550
3678
  fiberId: this.id,
3551
3679
  scopeId: this.scopeId,
3552
- traceId: _optionalChain([this, 'access', _197 => _197.fiberContext, 'optionalAccess', _198 => _198.trace, 'optionalAccess', _199 => _199.traceId]),
3553
- spanId: _optionalChain([this, 'access', _200 => _200.fiberContext, 'optionalAccess', _201 => _201.trace, 'optionalAccess', _202 => _202.spanId]),
3554
- parentSpanId: _optionalChain([this, 'access', _203 => _203.fiberContext, 'optionalAccess', _204 => _204.trace, 'optionalAccess', _205 => _205.parentSpanId]),
3555
- traceState: _optionalChain([this, 'access', _206 => _206.fiberContext, 'optionalAccess', _207 => _207.trace, 'optionalAccess', _208 => _208.traceState]),
3556
- baggage: _optionalChain([this, 'access', _209 => _209.fiberContext, 'optionalAccess', _210 => _210.trace, 'optionalAccess', _211 => _211.baggage]),
3557
- sampled: _optionalChain([this, 'access', _212 => _212.fiberContext, 'optionalAccess', _213 => _213.trace, 'optionalAccess', _214 => _214.sampled])
3680
+ traceId: _optionalChain([this, 'access', _201 => _201.fiberContext, 'optionalAccess', _202 => _202.trace, 'optionalAccess', _203 => _203.traceId]),
3681
+ spanId: _optionalChain([this, 'access', _204 => _204.fiberContext, 'optionalAccess', _205 => _205.trace, 'optionalAccess', _206 => _206.spanId]),
3682
+ parentSpanId: _optionalChain([this, 'access', _207 => _207.fiberContext, 'optionalAccess', _208 => _208.trace, 'optionalAccess', _209 => _209.parentSpanId]),
3683
+ traceState: _optionalChain([this, 'access', _210 => _210.fiberContext, 'optionalAccess', _211 => _211.trace, 'optionalAccess', _212 => _212.traceState]),
3684
+ baggage: _optionalChain([this, 'access', _213 => _213.fiberContext, 'optionalAccess', _214 => _214.trace, 'optionalAccess', _215 => _215.baggage]),
3685
+ sampled: _optionalChain([this, 'access', _216 => _216.fiberContext, 'optionalAccess', _217 => _217.trace, 'optionalAccess', _218 => _218.sampled])
3558
3686
  });
3559
3687
  }
3560
3688
  addFinalizer(f) {
@@ -3619,7 +3747,7 @@ var RuntimeFiber = (_class17 = class {
3619
3747
  unsafeRunAsync(eff, this.env, () => {
3620
3748
  });
3621
3749
  }
3622
- } catch (e12) {
3750
+ } catch (e13) {
3623
3751
  }
3624
3752
  }
3625
3753
  }
@@ -3808,7 +3936,7 @@ var RuntimeFiber = (_class17 = class {
3808
3936
  this._asyncDetach = void 0;
3809
3937
  try {
3810
3938
  canceler();
3811
- } catch (e13) {
3939
+ } catch (e14) {
3812
3940
  }
3813
3941
  });
3814
3942
  }
@@ -3893,7 +4021,7 @@ var RuntimeFiber = (_class17 = class {
3893
4021
  syncTrampoline() {
3894
4022
  while (this.budget-- > 0) {
3895
4023
  let cur = this.current;
3896
- while (cur._tag === "FlatMap" && _optionalChain([cur, 'access', _215 => _215.first, 'optionalAccess', _216 => _216._tag]) === "FlatMap") {
4024
+ while (cur._tag === "FlatMap" && _optionalChain([cur, 'access', _219 => _219.first, 'optionalAccess', _220 => _220._tag]) === "FlatMap") {
3897
4025
  this.stack.push({ _tag: "SuccessCont", k: cur.andThen });
3898
4026
  cur = cur.first;
3899
4027
  }
@@ -3963,7 +4091,7 @@ var RuntimeFiber = (_class17 = class {
3963
4091
  this._asyncDetach = void 0;
3964
4092
  try {
3965
4093
  canceler();
3966
- } catch (e14) {
4094
+ } catch (e15) {
3967
4095
  }
3968
4096
  });
3969
4097
  }
@@ -3994,7 +4122,7 @@ function getCurrentFiber() {
3994
4122
  }
3995
4123
  function unsafeGetCurrentRuntime() {
3996
4124
  const f = getCurrentFiber();
3997
- if (!_optionalChain([f, 'optionalAccess', _217 => _217.runtime])) {
4125
+ if (!_optionalChain([f, 'optionalAccess', _221 => _221.runtime])) {
3998
4126
  throw new Error("unsafeGetCurrentRuntime: no current fiber/runtime");
3999
4127
  }
4000
4128
  return f.runtime;
@@ -4060,7 +4188,7 @@ var Scope = (_class19 = class _Scope {
4060
4188
  this.runtime = runtime;
4061
4189
  this.parentScopeId = parentScopeId;
4062
4190
  this.id = nextScopeId++;
4063
- const inferredParent = _nullishCoalesce(this.parentScopeId, () => ( _optionalChain([getCurrentFiber, 'call', _218 => _218(), 'optionalAccess', _219 => _219.scopeId])));
4191
+ const inferredParent = _nullishCoalesce(this.parentScopeId, () => ( _optionalChain([getCurrentFiber, 'call', _222 => _222(), 'optionalAccess', _223 => _223.scopeId])));
4064
4192
  if (this.runtime.hasActiveHooks()) {
4065
4193
  this.runtime.emit({
4066
4194
  type: "scope.open",
@@ -4111,7 +4239,7 @@ var Scope = (_class19 = class _Scope {
4111
4239
  type: "scope.close",
4112
4240
  scopeId: this.id,
4113
4241
  status,
4114
- error: _optionalChain([failure, 'optionalAccess', _220 => _220._tag]) === "Some" ? failure.value : exit._tag === "Failure" ? exit.cause : void 0
4242
+ error: _optionalChain([failure, 'optionalAccess', _224 => _224._tag]) === "Some" ? failure.value : exit._tag === "Failure" ? exit.cause : void 0
4115
4243
  });
4116
4244
  }
4117
4245
  }
@@ -4135,7 +4263,7 @@ var Scope = (_class19 = class _Scope {
4135
4263
  let result;
4136
4264
  try {
4137
4265
  result = fin(exit);
4138
- } catch (e15) {
4266
+ } catch (e16) {
4139
4267
  return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
4140
4268
  }
4141
4269
  if (result._tag === "Succeed") {
@@ -4269,4 +4397,7 @@ function withScope(runtime, f) {
4269
4397
 
4270
4398
 
4271
4399
 
4272
- 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; exports.Scope = Scope; exports.withScopeAsync = withScopeAsync; exports.withScope = withScope;
4400
+
4401
+
4402
+
4403
+ exports.PushStatus = PushStatus; exports.RingBuffer = RingBuffer; exports.resolveWasmModule = resolveWasmModule; exports.makeBoundedRingBuffer = makeBoundedRingBuffer; exports.sanitizeLaneKey = sanitizeLaneKey; exports.laneTag = laneTag; exports.inferCallerLaneFromStack = inferCallerLaneFromStack; exports.Scheduler = Scheduler; exports.globalScheduler = globalScheduler; exports.emptyContext = emptyContext; exports.ctxExtend = ctxExtend; exports.ctxToObject = ctxToObject; exports.DefaultHostExecutor = DefaultHostExecutor; exports.JsFiberEngine = JsFiberEngine; exports.HostRegistry = HostRegistry; exports.ProgramBuilder = ProgramBuilder; exports.EngineFiberHandle = EngineFiberHandle; exports.ABI_VERSION = ABI_VERSION; exports.EVENT_WORDS = EVENT_WORDS; exports.NONE_U32 = NONE_U32; exports.OpcodeTagCode = OpcodeTagCode; exports.EventKindCode = EventKindCode; exports.encodeOpcodeProgram = encodeOpcodeProgram; exports.encodeOpcodeNodes = encodeOpcodeNodes; exports.decodeEvent = decodeEvent; exports.decodeEventBatch = decodeEventBatch; exports.WasmPackFiberBridge = WasmPackFiberBridge; exports.WasmFiberRegistryBridge = WasmFiberRegistryBridge; exports.makeFiberReadyQueue = makeFiberReadyQueue; exports.WasmFiberEngine = WasmFiberEngine; exports.runtimeCapabilities = runtimeCapabilities; exports.liveClock = liveClock; exports.runtimeClockFromEnv = runtimeClockFromEnv; exports.NoopHooks = NoopHooks; exports.Runtime = Runtime; exports.fork = fork; exports.runtimeForCaller = runtimeForCaller; exports.toPromiseByCaller = toPromiseByCaller; exports.unsafeRunAsync = unsafeRunAsync; exports.toPromise = toPromise; exports.setAbortablePromisePerLabelTracking = setAbortablePromisePerLabelTracking; exports.recordAbortablePromiseStart = recordAbortablePromiseStart; exports.recordAbortablePromiseFinish = recordAbortablePromiseFinish; exports.abortablePromiseStats = abortablePromiseStats; exports.resetAbortablePromiseStats = resetAbortablePromiseStats; exports.fromPromiseAbortable = fromPromiseAbortable; exports.unsafeRunFoldWithEnv = unsafeRunFoldWithEnv; exports.setBenchmarkBudget = setBenchmarkBudget; exports.getBenchmarkBudget = getBenchmarkBudget; exports.RuntimeFiber = RuntimeFiber; exports.getCurrentFiber = getCurrentFiber; exports.unsafeGetCurrentRuntime = unsafeGetCurrentRuntime; exports.withCurrentFiber = withCurrentFiber; exports.Scope = Scope; exports.withScopeAsync = withScopeAsync; exports.withScope = withScope;