brass-runtime 1.19.0 → 1.19.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 (78) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/agent/cli/main.cjs +30 -30
  3. package/dist/agent/cli/main.js +2 -2
  4. package/dist/agent/cli/main.mjs +2 -2
  5. package/dist/agent/index.cjs +3 -3
  6. package/dist/agent/index.d.ts +1 -1
  7. package/dist/agent/index.js +2 -2
  8. package/dist/agent/index.mjs +2 -2
  9. package/dist/{chunk-GOEO763K.cjs → chunk-2XXQ3NVT.cjs} +19 -19
  10. package/dist/{chunk-5RVHSBJ6.mjs → chunk-5X3MPWTR.mjs} +275 -39
  11. package/dist/{chunk-2R3RVNS2.js → chunk-6AGAZD32.js} +6 -6
  12. package/dist/{chunk-BLXBZ6RE.mjs → chunk-6BNZS2A4.mjs} +1 -1
  13. package/dist/{chunk-EXBGIC66.js → chunk-6W5DC3TX.js} +1 -1
  14. package/dist/{chunk-MUMBUXU6.mjs → chunk-BFNBU47C.mjs} +22 -6
  15. package/dist/{chunk-JWFOWPMB.js → chunk-BHX4MD35.js} +5 -5
  16. package/dist/{chunk-OO7BGCC3.cjs → chunk-CXWJII2N.cjs} +13 -13
  17. package/dist/{chunk-Z2YIDHRI.cjs → chunk-ENMKEX3N.cjs} +5 -5
  18. package/dist/{chunk-RZGB3DXR.js → chunk-HKLZJ5UK.js} +275 -39
  19. package/dist/{chunk-HW2CLRJ3.mjs → chunk-IA6BDGXW.mjs} +6 -6
  20. package/dist/{chunk-MA74OYCI.cjs → chunk-IHY2EJTT.cjs} +6 -6
  21. package/dist/{chunk-AQQQFNYD.mjs → chunk-IWAQQDYE.mjs} +1 -1
  22. package/dist/{chunk-C3CWI42G.js → chunk-J4F5KC3U.js} +1 -1
  23. package/dist/{chunk-ZDZNV6NA.cjs → chunk-JKHBEWQA.cjs} +23 -7
  24. package/dist/{chunk-5UBJT4RW.mjs → chunk-JM7WMSRR.mjs} +3 -3
  25. package/dist/{chunk-YQWZ7FZX.cjs → chunk-JQCQWO47.cjs} +5 -5
  26. package/dist/{chunk-B2VXVNIS.js → chunk-LI7WUVJN.js} +1 -1
  27. package/dist/{chunk-FC5N5QHJ.js → chunk-NWONRWBT.js} +2 -2
  28. package/dist/{chunk-H4ZRUQZL.js → chunk-PG6CHG34.js} +3 -3
  29. package/dist/{chunk-NQW3YUFN.cjs → chunk-QAHW7S3Q.cjs} +18 -18
  30. package/dist/{chunk-GXOIUBKE.js → chunk-RZQK32C6.js} +2 -2
  31. package/dist/{chunk-EKLEDIVJ.mjs → chunk-S6KSHYAT.mjs} +2 -2
  32. package/dist/{chunk-URVS2OE2.mjs → chunk-SCHM2MDA.mjs} +2 -2
  33. package/dist/{chunk-A6EG5WRL.js → chunk-TAPB4NN5.js} +2 -2
  34. package/dist/{chunk-APQBU7TM.js → chunk-TN2P7RNK.js} +22 -6
  35. package/dist/{chunk-QBVS3UYN.cjs → chunk-TWEHIAUE.cjs} +54 -54
  36. package/dist/{chunk-7FZUTJM3.cjs → chunk-UOKXJQAI.cjs} +380 -144
  37. package/dist/{chunk-FYWWU3Z7.cjs → chunk-VXNWVAIG.cjs} +2 -2
  38. package/dist/{chunk-KAPZHDO4.mjs → chunk-WA65XP2P.mjs} +1 -1
  39. package/dist/{chunk-4PKBNG2H.js → chunk-XO3TDAJE.js} +1 -1
  40. package/dist/{chunk-KDXNWGPB.mjs → chunk-XRRC5BBM.mjs} +1 -1
  41. package/dist/{chunk-DV644N7P.cjs → chunk-ZJC3JZIE.cjs} +16 -16
  42. package/dist/{chunk-3NKXUX4T.mjs → chunk-ZXLETUGQ.mjs} +2 -2
  43. package/dist/{chunk-OX6MF7SZ.mjs → chunk-ZXXOXB3T.mjs} +5 -5
  44. package/dist/{chunk-6STX4PS3.cjs → chunk-ZZ2CMYJL.cjs} +13 -13
  45. package/dist/core/index.cjs +9 -7
  46. package/dist/core/index.d.ts +6 -6
  47. package/dist/core/index.js +8 -6
  48. package/dist/core/index.mjs +8 -6
  49. package/dist/{defaultClient-Cid0JoUR.d.ts → defaultClient-hyVSNzSJ.d.ts} +3 -3
  50. package/dist/{effect-DnGUuhw6.d.ts → effect-DbEMiMvv.d.ts} +8 -1
  51. package/dist/http/index.cjs +48 -48
  52. package/dist/http/index.d.ts +8 -8
  53. package/dist/http/index.js +6 -6
  54. package/dist/http/index.mjs +6 -6
  55. package/dist/http/testing.cjs +8 -8
  56. package/dist/http/testing.d.ts +4 -4
  57. package/dist/http/testing.js +4 -4
  58. package/dist/http/testing.mjs +4 -4
  59. package/dist/index.cjs +87 -85
  60. package/dist/index.d.ts +7 -7
  61. package/dist/index.js +9 -7
  62. package/dist/index.mjs +9 -7
  63. package/dist/{layer-D2LFcBVx.d.ts → layer-CsNGeVee.d.ts} +1 -1
  64. package/dist/observability/index.cjs +9 -9
  65. package/dist/observability/index.d.ts +7 -7
  66. package/dist/observability/index.js +8 -8
  67. package/dist/observability/index.mjs +8 -8
  68. package/dist/perf/cli.cjs +25 -25
  69. package/dist/perf/cli.js +10 -10
  70. package/dist/perf/cli.mjs +10 -10
  71. package/dist/perf/index.cjs +12 -12
  72. package/dist/perf/index.js +10 -10
  73. package/dist/perf/index.mjs +10 -10
  74. package/dist/{server-Bf1zNYZk.d.ts → server-BKKuzAW9.d.ts} +4 -4
  75. package/dist/{stream-I7bkvF7a.d.ts → stream-B8c_UKZq.d.ts} +1 -1
  76. package/dist/{tracer-DF83nLn6.d.ts → tracer-CS3yOXZx.d.ts} +2 -2
  77. package/dist/{tracing-CWV4gT0u.d.ts → tracing-DIAUf2x8.d.ts} +1 -1
  78. package/package.json +1 -1
@@ -3,18 +3,20 @@ import {
3
3
  } from "./chunk-MOO4L7F4.mjs";
4
4
  import {
5
5
  streamFromReadableStream
6
- } from "./chunk-AQQQFNYD.mjs";
6
+ } from "./chunk-IWAQQDYE.mjs";
7
7
  import {
8
8
  layerEffect,
9
9
  makeScheduleDriver,
10
10
  makeServiceTag,
11
11
  sleep
12
- } from "./chunk-KDXNWGPB.mjs";
12
+ } from "./chunk-XRRC5BBM.mjs";
13
13
  import {
14
14
  fromPromiseAbortable,
15
+ recordAbortablePromiseFinish,
16
+ recordAbortablePromiseStart,
15
17
  resolveWasmModule,
16
18
  toPromise
17
- } from "./chunk-MUMBUXU6.mjs";
19
+ } from "./chunk-BFNBU47C.mjs";
18
20
  import {
19
21
  Cause,
20
22
  asyncEffect,
@@ -3182,6 +3184,275 @@ var noopSignal = (() => {
3182
3184
  globalThis.__brassNoopSignal = s;
3183
3185
  return s;
3184
3186
  })();
3187
+ var PoolRequestState = class {
3188
+ constructor(req, url, transport, metrics, pool, adaptiveLimiter, timerWheel, timeoutMs, env, cb, previousSignal, controller, signal, label, startedAt) {
3189
+ this.req = req;
3190
+ this.url = url;
3191
+ this.transport = transport;
3192
+ this.metrics = metrics;
3193
+ this.pool = pool;
3194
+ this.adaptiveLimiter = adaptiveLimiter;
3195
+ this.timerWheel = timerWheel;
3196
+ this.timeoutMs = timeoutMs;
3197
+ this.env = env;
3198
+ this.cb = cb;
3199
+ this.previousSignal = previousSignal;
3200
+ this.controller = controller;
3201
+ this.signal = signal;
3202
+ this.label = label;
3203
+ this.startedAt = startedAt;
3204
+ }
3205
+ req;
3206
+ url;
3207
+ transport;
3208
+ metrics;
3209
+ pool;
3210
+ adaptiveLimiter;
3211
+ timerWheel;
3212
+ timeoutMs;
3213
+ env;
3214
+ cb;
3215
+ previousSignal;
3216
+ controller;
3217
+ signal;
3218
+ label;
3219
+ startedAt;
3220
+ done = false;
3221
+ cancelInner = void 0;
3222
+ timerHandle = void 0;
3223
+ timeoutHandle = void 0;
3224
+ lease = void 0;
3225
+ finish(outcome, exit, error) {
3226
+ if (this.done) return;
3227
+ this.done = true;
3228
+ if (this.timerHandle) {
3229
+ this.timerHandle.cancel();
3230
+ this.timerHandle = void 0;
3231
+ }
3232
+ if (this.timeoutHandle !== void 0) {
3233
+ clearTimeout(this.timeoutHandle);
3234
+ this.timeoutHandle = void 0;
3235
+ }
3236
+ if (this.previousSignal) this.previousSignal.removeEventListener("abort", this.boundAbortFromPrevious);
3237
+ this.cancelInner = void 0;
3238
+ recordAbortablePromiseFinish(this.label, outcome);
3239
+ this.metrics.onFinish({
3240
+ label: this.label,
3241
+ outcome,
3242
+ durationMs: Math.round(performance.now() - this.startedAt),
3243
+ error
3244
+ });
3245
+ this.cb(exit);
3246
+ }
3247
+ finishFailure(error, outcome = "failure") {
3248
+ this.finish(outcome, { _tag: "Failure", cause: Cause.fail(error) }, error);
3249
+ }
3250
+ abortCurrent(reason) {
3251
+ if (!this.controller) return;
3252
+ try {
3253
+ this.controller.abort(reason);
3254
+ } catch {
3255
+ this.controller.abort();
3256
+ }
3257
+ }
3258
+ /**
3259
+ * Bound reference for addEventListener/removeEventListener.
3260
+ * Only allocated when previousSignal is present (not on the hot path).
3261
+ */
3262
+ boundAbortFromPrevious = void 0;
3263
+ abortFromPrevious() {
3264
+ const error = this.previousSignal ? abortErrorForSignal(this.previousSignal) : { _tag: "Abort" };
3265
+ this.abortCurrent(this.previousSignal?.reason);
3266
+ const cancel = this.cancelInner;
3267
+ this.cancelInner = void 0;
3268
+ if (this.lease) {
3269
+ releaseFailure(this.lease, this.adaptiveLimiter);
3270
+ this.lease = void 0;
3271
+ }
3272
+ queueMicrotask(() => {
3273
+ this.finishFailure(error);
3274
+ cancel?.();
3275
+ });
3276
+ }
3277
+ runTransportInner() {
3278
+ const { transport, req, url, signal, env } = this;
3279
+ try {
3280
+ const effect = transport({ request: req, url, signal });
3281
+ if (effect._tag === "Succeed") {
3282
+ if (this.lease) releaseSuccess(this.lease, this.adaptiveLimiter, effect.value);
3283
+ this.finish("success", { _tag: "Success", value: effect.value });
3284
+ } else if (effect._tag === "Fail") {
3285
+ if (this.lease) releaseFailure(this.lease, this.adaptiveLimiter);
3286
+ this.finishFailure(effect.error);
3287
+ } else if (effect._tag === "Async") {
3288
+ try {
3289
+ const cancel = effect.register(env, (exit) => {
3290
+ if (this.done) return;
3291
+ this.cancelInner = void 0;
3292
+ if (exit._tag === "Success") {
3293
+ if (this.lease) releaseSuccess(this.lease, this.adaptiveLimiter, exit.value);
3294
+ this.finish("success", exit);
3295
+ } else {
3296
+ if (this.lease) releaseFailure(this.lease, this.adaptiveLimiter);
3297
+ this.finish("failure", exit, exitError(exit));
3298
+ }
3299
+ });
3300
+ if (!this.done) this.cancelInner = typeof cancel === "function" ? cancel : void 0;
3301
+ } catch (error) {
3302
+ if (this.lease) releaseFailure(this.lease, this.adaptiveLimiter);
3303
+ this.finishFailure(normalizeHttpError(error));
3304
+ }
3305
+ } else {
3306
+ const innerCancel = registerHttpEffect(
3307
+ effect,
3308
+ env,
3309
+ (exit) => {
3310
+ if (this.done) return;
3311
+ this.cancelInner = void 0;
3312
+ if (exit._tag === "Success") {
3313
+ if (this.lease) releaseSuccess(this.lease, this.adaptiveLimiter, exit.value);
3314
+ this.finish("success", exit);
3315
+ } else {
3316
+ if (this.lease) releaseFailure(this.lease, this.adaptiveLimiter);
3317
+ this.finish("failure", exit, exitError(exit));
3318
+ }
3319
+ }
3320
+ );
3321
+ if (!this.done) this.cancelInner = innerCancel;
3322
+ }
3323
+ } catch (error) {
3324
+ if (this.lease) releaseFailure(this.lease, this.adaptiveLimiter);
3325
+ this.finishFailure(normalizeHttpError(error));
3326
+ }
3327
+ }
3328
+ };
3329
+ var runPoolTransport = (req, url, transport, metrics, pool, adaptiveLimiter, timerWheel, timeoutMs) => ({
3330
+ _tag: "Async",
3331
+ register: (env, cb) => {
3332
+ const previousSignal = req.init?.signal;
3333
+ const controller = new AbortController();
3334
+ const signal = controller.signal;
3335
+ const label = fetchLabel(req, url);
3336
+ const startedAt = performance.now();
3337
+ const state = new PoolRequestState(
3338
+ req,
3339
+ url,
3340
+ transport,
3341
+ metrics,
3342
+ pool,
3343
+ adaptiveLimiter,
3344
+ timerWheel,
3345
+ timeoutMs,
3346
+ env,
3347
+ cb,
3348
+ previousSignal,
3349
+ controller,
3350
+ signal,
3351
+ label,
3352
+ startedAt
3353
+ );
3354
+ recordAbortablePromiseStart(label);
3355
+ metrics.onStart();
3356
+ if (previousSignal) {
3357
+ state.boundAbortFromPrevious = () => state.abortFromPrevious();
3358
+ if (previousSignal.aborted) {
3359
+ state.abortFromPrevious();
3360
+ return () => void 0;
3361
+ }
3362
+ previousSignal.addEventListener("abort", state.boundAbortFromPrevious, ONCE_OPTIONS);
3363
+ }
3364
+ if (timeoutMs !== void 0 && timeoutMs > 0) {
3365
+ const onTimeout = () => {
3366
+ const reason = timeoutReason(req, url, timeoutMs);
3367
+ if (state.lease) {
3368
+ releaseFailure(state.lease, adaptiveLimiter);
3369
+ state.lease = void 0;
3370
+ }
3371
+ const cancel = state.cancelInner;
3372
+ state.cancelInner = void 0;
3373
+ state.finishFailure(reason, "timeout");
3374
+ state.abortCurrent(reason);
3375
+ cancel?.();
3376
+ };
3377
+ if (timerWheel) {
3378
+ state.timerHandle = timerWheel.schedule(timeoutMs, onTimeout, startedAt);
3379
+ } else {
3380
+ state.timeoutHandle = setTimeout(onTimeout, timeoutMs);
3381
+ }
3382
+ }
3383
+ if (adaptiveLimiter) {
3384
+ const key = resolveHttpPoolKey(adaptiveLimiter.keyResolver, req, url);
3385
+ const syncLease = adaptiveLimiter.tryAcquireSync(key, signal);
3386
+ if (syncLease) {
3387
+ state.lease = syncLease;
3388
+ } else {
3389
+ adaptiveLimiter.acquire(key, signal, { priority: requestPriority(req) }).then(
3390
+ (asyncLease) => {
3391
+ if (state.done) {
3392
+ asyncLease.release(0);
3393
+ return;
3394
+ }
3395
+ state.lease = asyncLease;
3396
+ state.runTransportInner();
3397
+ },
3398
+ (err) => {
3399
+ if (state.done) return;
3400
+ state.finishFailure(normalizeHttpError(err));
3401
+ }
3402
+ );
3403
+ return () => {
3404
+ if (state.done) return;
3405
+ const cancel = state.cancelInner;
3406
+ state.cancelInner = void 0;
3407
+ state.abortCurrent();
3408
+ if (state.lease) releaseFailure(state.lease, adaptiveLimiter);
3409
+ state.finish("interrupt", { _tag: "Failure", cause: Cause.interrupt() });
3410
+ cancel?.();
3411
+ };
3412
+ }
3413
+ } else if (pool) {
3414
+ const key = resolveHttpPoolKey(pool.keyResolver, req, url);
3415
+ const syncLease = pool.tryAcquireSync(key, signal);
3416
+ if (syncLease) {
3417
+ state.lease = syncLease;
3418
+ } else {
3419
+ pool.acquire(key, signal).then(
3420
+ (asyncLease) => {
3421
+ if (state.done) {
3422
+ asyncLease.release();
3423
+ return;
3424
+ }
3425
+ state.lease = asyncLease;
3426
+ state.runTransportInner();
3427
+ },
3428
+ (err) => {
3429
+ if (state.done) return;
3430
+ state.finishFailure(normalizeHttpError(err));
3431
+ }
3432
+ );
3433
+ return () => {
3434
+ if (state.done) return;
3435
+ const cancel = state.cancelInner;
3436
+ state.cancelInner = void 0;
3437
+ state.abortCurrent();
3438
+ if (state.lease) releaseFailure(state.lease, void 0);
3439
+ state.finish("interrupt", { _tag: "Failure", cause: Cause.interrupt() });
3440
+ cancel?.();
3441
+ };
3442
+ }
3443
+ }
3444
+ state.runTransportInner();
3445
+ return () => {
3446
+ if (state.done) return;
3447
+ const cancel = state.cancelInner;
3448
+ state.cancelInner = void 0;
3449
+ state.abortCurrent();
3450
+ if (state.lease) releaseFailure(state.lease, adaptiveLimiter);
3451
+ state.finish("interrupt", { _tag: "Failure", cause: Cause.interrupt() });
3452
+ cancel?.();
3453
+ };
3454
+ }
3455
+ });
3185
3456
  function makeHttp(cfg = {}) {
3186
3457
  validateMakeHttpConfig(cfg);
3187
3458
  const baseUrl = cfg.baseUrl ?? "";
@@ -3200,42 +3471,7 @@ function makeHttp(cfg = {}) {
3200
3471
  if (!adaptiveLimiter && !pool && timeoutMs === void 0) {
3201
3472
  return runDirectTransport(req, url, transport, metrics);
3202
3473
  }
3203
- return fromPromiseAbortable(
3204
- async (signal, env) => {
3205
- let lease;
3206
- const linkedSignal = linkAbortSignals(signal, req.init?.signal);
3207
- try {
3208
- if (linkedSignal.signal.aborted) throw abortErrorForSignal(linkedSignal.signal);
3209
- if (adaptiveLimiter) {
3210
- const key = resolveHttpPoolKey(adaptiveLimiter.keyResolver, req, url);
3211
- lease = await adaptiveLimiter.acquire(key, linkedSignal.signal, { priority: requestPriority(req) });
3212
- } else if (pool) {
3213
- const key = resolveHttpPoolKey(pool.keyResolver, req, url);
3214
- lease = await pool.acquire(key, linkedSignal.signal);
3215
- }
3216
- const response = await runTransportEffect(
3217
- transport({ request: req, url, signal: linkedSignal.signal }),
3218
- env,
3219
- linkedSignal.signal
3220
- );
3221
- lease = releaseSuccess(lease, adaptiveLimiter, response);
3222
- return response;
3223
- } finally {
3224
- linkedSignal.cleanup();
3225
- if (lease) {
3226
- releaseFailure(lease, adaptiveLimiter);
3227
- }
3228
- }
3229
- },
3230
- normalizeHttpError,
3231
- {
3232
- label: fetchLabel(req, url),
3233
- timeoutMs,
3234
- timeoutReason: timeoutMs ? () => timeoutReason(req, url, timeoutMs) : void 0,
3235
- onStart: metrics.onStart,
3236
- onFinish: metrics.onFinish
3237
- }
3238
- );
3474
+ return runPoolTransport(req, url, transport, metrics, pool, adaptiveLimiter, void 0, timeoutMs);
3239
3475
  };
3240
3476
  const metadata = {};
3241
3477
  if (adaptiveLimiter) metadata.adaptiveLimiter = adaptiveLimiter;
@@ -1,24 +1,24 @@
1
1
  import {
2
2
  makeFiberRef,
3
3
  makeRuntimeRecorder
4
- } from "./chunk-GXOIUBKE.js";
4
+ } from "./chunk-RZQK32C6.js";
5
5
  import {
6
6
  withHttpObservability
7
- } from "./chunk-JWFOWPMB.js";
7
+ } from "./chunk-BHX4MD35.js";
8
8
  import {
9
9
  makeObservability
10
- } from "./chunk-A6EG5WRL.js";
10
+ } from "./chunk-TAPB4NN5.js";
11
11
  import {
12
12
  EventBus
13
- } from "./chunk-B2VXVNIS.js";
13
+ } from "./chunk-LI7WUVJN.js";
14
14
  import {
15
15
  makeDefaultHttpClient,
16
16
  makeHttp
17
- } from "./chunk-RZGB3DXR.js";
17
+ } from "./chunk-HKLZJ5UK.js";
18
18
  import {
19
19
  Runtime,
20
20
  Scheduler
21
- } from "./chunk-APQBU7TM.js";
21
+ } from "./chunk-TN2P7RNK.js";
22
22
  import {
23
23
  asyncFlatMap,
24
24
  asyncSucceed,
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  fromPromiseAbortable,
6
6
  withScopeAsync
7
- } from "./chunk-MUMBUXU6.mjs";
7
+ } from "./chunk-BFNBU47C.mjs";
8
8
  import {
9
9
  Cause,
10
10
  Exit,
@@ -3,7 +3,7 @@ import {
3
3
  liveClock,
4
4
  runtimeClockFromEnv,
5
5
  unsafeGetCurrentRuntime
6
- } from "./chunk-APQBU7TM.js";
6
+ } from "./chunk-TN2P7RNK.js";
7
7
  import {
8
8
  Async,
9
9
  Cause,
@@ -2860,7 +2860,9 @@ var Runtime = class _Runtime {
2860
2860
  this.forkPolicy = makeForkPolicy(this.env, this.hooks);
2861
2861
  this.fiberEngine = this.makeFiberEngine(this.engineMode, args.wasm);
2862
2862
  this.fallbackUsed = false;
2863
+ this.staticFastPathOk = this.hooks === NoopHooks && this.scheduler === globalScheduler && !this.inferLane && this.engineMode === "ts";
2863
2864
  }
2865
+ staticFastPathOk;
2864
2866
  makeFiberEngine(mode, wasm) {
2865
2867
  if (mode === "ts") return new JsFiberEngine(this);
2866
2868
  if (mode === "wasm") return new WasmFiberEngine(this, wasm);
@@ -2990,11 +2992,8 @@ var Runtime = class _Runtime {
2990
2992
  });
2991
2993
  }
2992
2994
  tryRunNativeTopLevel(effect, cb) {
2993
- if (this.hooks !== NoopHooks) return false;
2995
+ if (!this.staticFastPathOk) return false;
2994
2996
  if (getCurrentFiber() !== null) return false;
2995
- if (this.scheduler !== globalScheduler) return false;
2996
- if (this.inferLane) return false;
2997
- if (this.engineMode !== "ts") return false;
2998
2997
  new NativeTopLevelRunner(this, effect, cb).start();
2999
2998
  return true;
3000
2999
  }
@@ -3070,16 +3069,25 @@ var NativeTopLevelRunner = class {
3070
3069
  this.runLoop();
3071
3070
  }
3072
3071
  runLoop() {
3073
- this.withFrame(() => {
3072
+ const prevFiber = setCurrentFiber(this);
3073
+ try {
3074
3074
  this.yielded = false;
3075
3075
  let budget = NATIVE_FAST_PATH_STEP_BUDGET;
3076
3076
  while (!this.result && budget-- > 0) {
3077
3077
  const current = this.current;
3078
3078
  switch (current._tag) {
3079
3079
  case "Succeed":
3080
+ if (!this.stack || this.stack.length === 0) {
3081
+ this.notify(Exit.succeed(current.value));
3082
+ return;
3083
+ }
3080
3084
  this.onSuccess(current.value);
3081
3085
  break;
3082
3086
  case "Fail":
3087
+ if (!this.stack || this.stack.length === 0) {
3088
+ this.notify(Exit.failCause(Cause.fail(current.error)));
3089
+ return;
3090
+ }
3083
3091
  this.onCause(Cause.fail(current.error));
3084
3092
  break;
3085
3093
  case "Sync":
@@ -3156,7 +3164,9 @@ var NativeTopLevelRunner = class {
3156
3164
  this.yielded = true;
3157
3165
  queueMicrotask(() => this.runLoop());
3158
3166
  }
3159
- });
3167
+ } finally {
3168
+ setCurrentFiber(prevFiber);
3169
+ }
3160
3170
  }
3161
3171
  runAsync(current) {
3162
3172
  let registered = false;
@@ -4136,6 +4146,11 @@ function withCurrentFiber(fiber, f) {
4136
4146
  _current = prev;
4137
4147
  }
4138
4148
  }
4149
+ function setCurrentFiber(fiber) {
4150
+ const prev = _current;
4151
+ _current = fiber;
4152
+ return prev;
4153
+ }
4139
4154
 
4140
4155
  // src/core/runtime/engine/JsFiberEngine.ts
4141
4156
  var JsFiberEngine = class {
@@ -4397,6 +4412,7 @@ export {
4397
4412
  getCurrentFiber,
4398
4413
  unsafeGetCurrentRuntime,
4399
4414
  withCurrentFiber,
4415
+ setCurrentFiber,
4400
4416
  Scope,
4401
4417
  withScopeAsync,
4402
4418
  withScope
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RuntimeService
3
- } from "./chunk-FC5N5QHJ.js";
3
+ } from "./chunk-NWONRWBT.js";
4
4
  import {
5
5
  exemplarFromTraceContext,
6
6
  injectTraceContext,
@@ -13,26 +13,26 @@ import {
13
13
  spanEvent,
14
14
  validateHttpObservabilityOptions,
15
15
  withSpan
16
- } from "./chunk-A6EG5WRL.js";
16
+ } from "./chunk-TAPB4NN5.js";
17
17
  import {
18
18
  HttpClientService,
19
19
  getHttpRequestPolicy,
20
20
  httpErrorStatus,
21
21
  isRetryableHttpError,
22
22
  makeDefaultHttpClient
23
- } from "./chunk-RZGB3DXR.js";
23
+ } from "./chunk-HKLZJ5UK.js";
24
24
  import {
25
25
  registerHttpEffect
26
26
  } from "./chunk-TRM4JUZQ.js";
27
27
  import {
28
28
  layerEffect,
29
29
  makeServiceTag
30
- } from "./chunk-EXBGIC66.js";
30
+ } from "./chunk-6W5DC3TX.js";
31
31
  import {
32
32
  Runtime,
33
33
  fromPromiseAbortable,
34
34
  getCurrentFiber
35
- } from "./chunk-APQBU7TM.js";
35
+ } from "./chunk-TN2P7RNK.js";
36
36
  import {
37
37
  Cause,
38
38
  asyncEffect,
@@ -6,7 +6,7 @@ var _chunkSA6HUJVIcjs = require('./chunk-SA6HUJVI.cjs');
6
6
 
7
7
 
8
8
 
9
- var _chunkZDZNV6NAcjs = require('./chunk-ZDZNV6NA.cjs');
9
+ var _chunkJKHBEWQAcjs = require('./chunk-JKHBEWQA.cjs');
10
10
 
11
11
 
12
12
 
@@ -99,8 +99,8 @@ function makeMergePull(onLeft, onRight, flip, mergePullId) {
99
99
  const onLeftHandler = streamToRaceWithHandler("L", onLeft, onRight, flip, id);
100
100
  const onRightHandler = streamToRaceWithHandler("R", onLeft, onRight, flip, id);
101
101
  return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (_env, cb) => {
102
- const runtime = _chunkZDZNV6NAcjs.unsafeGetCurrentRuntime.call(void 0, );
103
- const scope = new (0, _chunkZDZNV6NAcjs.Scope)(runtime);
102
+ const runtime = _chunkJKHBEWQAcjs.unsafeGetCurrentRuntime.call(void 0, );
103
+ const scope = new (0, _chunkJKHBEWQAcjs.Scope)(runtime);
104
104
  const handler = _chunkSA6HUJVIcjs.raceWith.call(void 0,
105
105
  uncons(onLeft),
106
106
  uncons(onRight),
@@ -160,9 +160,9 @@ function uncons(self) {
160
160
  return makeMergePull(self.left, self.right, self.flip, 0);
161
161
  case "Scoped":
162
162
  return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env, cb) => {
163
- const runtime = _chunkZDZNV6NAcjs.unsafeGetCurrentRuntime.call(void 0, );
164
- const scope = new (0, _chunkZDZNV6NAcjs.Scope)(runtime);
165
- const fiber = _chunkZDZNV6NAcjs.getCurrentFiber.call(void 0, );
163
+ const runtime = _chunkJKHBEWQAcjs.unsafeGetCurrentRuntime.call(void 0, );
164
+ const scope = new (0, _chunkJKHBEWQAcjs.Scope)(runtime);
165
+ const fiber = _chunkJKHBEWQAcjs.getCurrentFiber.call(void 0, );
166
166
  _optionalChain([fiber, 'optionalAccess', _2 => _2.addFinalizer, 'call', _3 => _3((exit) => {
167
167
  try {
168
168
  scope.close(exit);
@@ -183,7 +183,7 @@ function uncons(self) {
183
183
  const wrap = (s) => fromPull(
184
184
  _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env2, cb2) => {
185
185
  const pull = uncons(s);
186
- _chunkZDZNV6NAcjs.unsafeRunFoldWithEnv.call(void 0,
186
+ _chunkJKHBEWQAcjs.unsafeRunFoldWithEnv.call(void 0,
187
187
  pull,
188
188
  env2,
189
189
  (cause) => {
@@ -206,14 +206,14 @@ function uncons(self) {
206
206
  }
207
207
  scope.addFinalizer((exit) => self.release(exit));
208
208
  const inner = ex.value;
209
- _chunkZDZNV6NAcjs.unsafeGetCurrentRuntime.call(void 0, ).fork(uncons(wrap(inner))).join(cb);
209
+ _chunkJKHBEWQAcjs.unsafeGetCurrentRuntime.call(void 0, ).fork(uncons(wrap(inner))).join(cb);
210
210
  });
211
211
  });
212
212
  case "Managed":
213
213
  return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env, cb) => {
214
- const runtime = _chunkZDZNV6NAcjs.unsafeGetCurrentRuntime.call(void 0, );
215
- const scope = new (0, _chunkZDZNV6NAcjs.Scope)(runtime);
216
- _optionalChain([_chunkZDZNV6NAcjs.getCurrentFiber.call(void 0, ), 'optionalAccess', _4 => _4.addFinalizer, 'call', _5 => _5((exit) => {
214
+ const runtime = _chunkJKHBEWQAcjs.unsafeGetCurrentRuntime.call(void 0, );
215
+ const scope = new (0, _chunkJKHBEWQAcjs.Scope)(runtime);
216
+ _optionalChain([_chunkJKHBEWQAcjs.getCurrentFiber.call(void 0, ), 'optionalAccess', _4 => _4.addFinalizer, 'call', _5 => _5((exit) => {
217
217
  try {
218
218
  scope.close(exit);
219
219
  } catch (e4) {
@@ -241,7 +241,7 @@ function uncons(self) {
241
241
  scope.addFinalizer((exit) => release(exit));
242
242
  const wrap = (s) => fromPull(
243
243
  _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env2, cb2) => {
244
- _chunkZDZNV6NAcjs.unsafeRunFoldWithEnv.call(void 0,
244
+ _chunkJKHBEWQAcjs.unsafeRunFoldWithEnv.call(void 0,
245
245
  uncons(s),
246
246
  env2,
247
247
  (cause) => {
@@ -255,7 +255,7 @@ function uncons(self) {
255
255
  );
256
256
  })
257
257
  );
258
- _chunkZDZNV6NAcjs.unsafeGetCurrentRuntime.call(void 0, ).fork(uncons(wrap(inner))).join(cb);
258
+ _chunkJKHBEWQAcjs.unsafeGetCurrentRuntime.call(void 0, ).fork(uncons(wrap(inner))).join(cb);
259
259
  });
260
260
  });
261
261
  }
@@ -1,22 +1,22 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunk6STX4PS3cjs = require('./chunk-6STX4PS3.cjs');
4
+ var _chunkZZ2CMYJLcjs = require('./chunk-ZZ2CMYJL.cjs');
5
5
 
6
6
 
7
- var _chunkZDZNV6NAcjs = require('./chunk-ZDZNV6NA.cjs');
7
+ var _chunkJKHBEWQAcjs = require('./chunk-JKHBEWQA.cjs');
8
8
 
9
9
 
10
10
  var _chunkMVGUEJ5Zcjs = require('./chunk-MVGUEJ5Z.cjs');
11
11
 
12
12
  // src/core/runtime/runtimeLayer.ts
13
- var RuntimeService = _chunk6STX4PS3cjs.makeServiceTag.call(void 0, "Runtime");
13
+ var RuntimeService = _chunkZZ2CMYJLcjs.makeServiceTag.call(void 0, "Runtime");
14
14
  function makeRuntimeLayer(env = {}, options = {}) {
15
15
  const { tag = RuntimeService, ...runtimeOptions } = options;
16
- return _chunk6STX4PS3cjs.layerEffect.call(void 0,
16
+ return _chunkZZ2CMYJLcjs.layerEffect.call(void 0,
17
17
  tag,
18
18
  (context) => _chunkMVGUEJ5Zcjs.asyncSync.call(void 0,
19
- () => new (0, _chunkZDZNV6NAcjs.Runtime)({
19
+ () => new (0, _chunkJKHBEWQAcjs.Runtime)({
20
20
  ...runtimeOptions,
21
21
  env: resolveRuntimeLayerEnv(env, context)
22
22
  })