better-effect 0.10.0 → 0.11.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.
Files changed (48) hide show
  1. package/README.md +244 -5
  2. package/dist/adapters/iti.d.mts +3 -4
  3. package/dist/adapters/iti.d.mts.map +1 -1
  4. package/dist/adapters/iti.mjs +9 -4
  5. package/dist/adapters/iti.mjs.map +1 -1
  6. package/dist/effect-2ZcGZI8A.mjs +513 -0
  7. package/dist/effect-2ZcGZI8A.mjs.map +1 -0
  8. package/dist/hono.d.mts +18 -13
  9. package/dist/hono.d.mts.map +1 -1
  10. package/dist/hono.mjs +9 -5
  11. package/dist/hono.mjs.map +1 -1
  12. package/dist/{index-BafDna0B.d.mts → index-C7Qild0_.d.mts} +158 -28
  13. package/dist/index-C7Qild0_.d.mts.map +1 -0
  14. package/dist/{index-DklNCz7w.d.mts → index-DStz0JMN.d.mts} +4 -4
  15. package/dist/{index-DklNCz7w.d.mts.map → index-DStz0JMN.d.mts.map} +1 -1
  16. package/dist/{index-CULgSzUw.d.mts → index-heuaRmXR.d.mts} +5 -5
  17. package/dist/{index-CULgSzUw.d.mts.map → index-heuaRmXR.d.mts.map} +1 -1
  18. package/dist/{index-C7KX5rAP.d.mts → index-rQhZk3Nt.d.mts} +127 -24
  19. package/dist/index-rQhZk3Nt.d.mts.map +1 -0
  20. package/dist/index.d.mts +4 -5
  21. package/dist/index.mjs +7 -538
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/runtime/explicit.d.mts +1 -1
  24. package/dist/runtime/node.d.mts +1 -1
  25. package/dist/runtime-DnMn0X0X.mjs +613 -0
  26. package/dist/runtime-DnMn0X0X.mjs.map +1 -0
  27. package/dist/scope-GGnmTQck.mjs +245 -0
  28. package/dist/scope-GGnmTQck.mjs.map +1 -0
  29. package/dist/{signal-C1bagvrO.mjs → signal-B97cs85Z.mjs} +81 -2
  30. package/dist/signal-B97cs85Z.mjs.map +1 -0
  31. package/dist/{standard-services-DW-i4UuA.mjs → standard-services-BFBq-4lo.mjs} +2 -2
  32. package/dist/{standard-services-DW-i4UuA.mjs.map → standard-services-BFBq-4lo.mjs.map} +1 -1
  33. package/dist/standard-services.d.mts +2 -2
  34. package/dist/standard-services.mjs +2 -2
  35. package/dist/testing.d.mts +198 -2
  36. package/dist/testing.d.mts.map +1 -0
  37. package/dist/testing.mjs +976 -2
  38. package/dist/testing.mjs.map +1 -0
  39. package/package.json +1 -1
  40. package/dist/effect-DAMqvegy.mjs +0 -544
  41. package/dist/effect-DAMqvegy.mjs.map +0 -1
  42. package/dist/index-BafDna0B.d.mts.map +0 -1
  43. package/dist/index-C7KX5rAP.d.mts.map +0 -1
  44. package/dist/map-layer-backend-gal-mcRv.mjs +0 -53
  45. package/dist/map-layer-backend-gal-mcRv.mjs.map +0 -1
  46. package/dist/map-layer-backend-rNwfH0Bz.d.mts +0 -42
  47. package/dist/map-layer-backend-rNwfH0Bz.d.mts.map +0 -1
  48. package/dist/signal-C1bagvrO.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import { a as ServiceTagCollisionError, c as ServiceNotFoundError, i as LayerRegistrationError, l as ServiceRuntimeNotConfiguredError, n as LayerDisposeError, o as CircularDependencyError, r as LayerGeneratorYieldError, s as ServiceAcquisitionError, t as DuplicateServiceError } from "./errors-Dnjhzbt0.mjs";
2
- import { h as RuntimeContextNotConfiguredError, i as getRuntimeContext, l as makeRuntimeContext, u as runRuntimeContext } from "./context-BUEf1qjL.mjs";
3
- import { a as ServiceRuntime, i as Service, n as linkAbortSignals, o as defaultRuntimeContextStorage, r as Layer, t as CurrentAbortSignal } from "./signal-C1bagvrO.mjs";
4
- import { t as MapLayerBackend } from "./map-layer-backend-gal-mcRv.mjs";
5
- import { a as ScopeRuntime, c as ScopeCloseError, i as runScoped, l as ScopeClosedError, n as Program, o as disposeResource, r as Scope, s as ResourceNotDisposableError, t as Effect, u as ScopeRuntimeNotConfiguredError } from "./effect-DAMqvegy.mjs";
6
- import { Err, Result, TaggedError } from "better-result";
2
+ import { h as RuntimeContextNotConfiguredError } from "./context-BUEf1qjL.mjs";
3
+ import { c as ScopeClosedError, d as ServiceRuntime, i as disposeResource, l as ScopeRuntimeNotConfiguredError, o as ResourceNotDisposableError, r as Layer, s as ScopeCloseError, t as CurrentAbortSignal, u as Service } from "./signal-B97cs85Z.mjs";
4
+ import { t as Scope } from "./scope-GGnmTQck.mjs";
5
+ import { i as MapLayerBackend, n as RuntimeObserver, t as Runtime } from "./runtime-DnMn0X0X.mjs";
6
+ import { n as Program, t as Effect } from "./effect-2ZcGZI8A.mjs";
7
+ import { Result, TaggedError } from "better-result";
7
8
  //#region src/function/pipe.ts
8
9
  function pipe(value, ...operations) {
9
10
  return operations.reduce((current, operation) => operation(current), value);
@@ -86,538 +87,6 @@ const Resource = {
86
87
  /** Acquire, use, and release a resource with deterministic error precedence. */
87
88
  acquireUseRelease };
88
89
  //#endregion
89
- //#region src/runtime/outcome.ts
90
- /** Classify only a nominal better-result Err as a failed Runtime outcome. */
91
- const classifyRuntimeOutcome = (value) => {
92
- if (value instanceof Err) return {
93
- status: "failure",
94
- cause: value.error
95
- };
96
- return { status: "success" };
97
- };
98
- //#endregion
99
- //#region src/runtime/observer.ts
100
- const notifyRuntimeObservers = (observers, select, event) => {
101
- for (const observer of observers) {
102
- const callback = select(observer);
103
- if (!callback) continue;
104
- try {
105
- Promise.resolve(callback(event)).catch(() => {});
106
- } catch {}
107
- }
108
- };
109
- //#endregion
110
- //#region src/layer/resolution.ts
111
- const findCycleStart = (path, token) => path.findIndex((current) => current.serviceTag === token.serviceTag);
112
- const shouldPreserve = (cause) => cause instanceof CircularDependencyError || cause instanceof ServiceAcquisitionError || cause instanceof ServiceNotFoundError || cause instanceof ServiceTagCollisionError;
113
- /** Wrap a backend with Runtime-local resolution paths and acquisition errors. */
114
- const createResolutionResolver = (resolver, storage = defaultRuntimeContextStorage, observers = []) => {
115
- const wrapped = { async resolve(token) {
116
- const context = getRuntimeContext(storage);
117
- const path = context?.resolutionPath ?? [];
118
- const cycleStart = findCycleStart(path, token);
119
- const resolutionPath = [...path, token];
120
- const notifyResolve = (outcome) => {
121
- notifyRuntimeObservers(observers, (observer) => observer.onServiceResolve, {
122
- service: token,
123
- resolutionPath,
124
- outcome
125
- });
126
- };
127
- if (cycleStart >= 0) {
128
- const error = new CircularDependencyError([...path.slice(cycleStart), token]);
129
- notifyResolve({
130
- status: "failure",
131
- cause: error
132
- });
133
- throw error;
134
- }
135
- const nextContext = makeRuntimeContext(wrapped, context?.scope, resolutionPath, context?.signal, context);
136
- return await runRuntimeContext(storage, nextContext, async () => {
137
- try {
138
- const instance = await resolver.resolve(token);
139
- notifyResolve({ status: "success" });
140
- return instance;
141
- } catch (cause) {
142
- if (shouldPreserve(cause)) {
143
- notifyResolve({
144
- status: "failure",
145
- cause
146
- });
147
- throw cause;
148
- }
149
- const error = new ServiceAcquisitionError(token, resolutionPath, cause);
150
- notifyResolve({
151
- status: "failure",
152
- cause: error
153
- });
154
- throw error;
155
- }
156
- });
157
- } };
158
- return wrapped;
159
- };
160
- //#endregion
161
- //#region src/layer/runtime.ts
162
- const SCOPE_SUCCESS = Object.freeze({ status: "success" });
163
- var RuntimeHandleDisposedError = class extends Error {
164
- constructor() {
165
- super("Cannot run a program using a disposed Layer");
166
- this.name = "RuntimeHandleDisposedError";
167
- }
168
- };
169
- const normalizeDisposeCauses = (cause) => {
170
- if (cause instanceof AggregateError) return [...cause.errors];
171
- return [cause];
172
- };
173
- const isScopeOutcome = (input) => input !== void 0 && "status" in input;
174
- const validateDisposeOptions = (options) => {
175
- const { gracePeriod } = options;
176
- if (gracePeriod !== void 0 && (!Number.isFinite(gracePeriod) || gracePeriod < 0)) throw new RangeError("Runtime dispose gracePeriod must be a finite non-negative number");
177
- };
178
- const notifyShutdownFailure = async (observer, diagnostic) => {
179
- if (!observer) return;
180
- try {
181
- await observer(diagnostic);
182
- } catch {}
183
- };
184
- const bindProviderToScope = (provider, scope, contextStorage, resolver, observers) => ({
185
- service: provider.service,
186
- acquire: () => {
187
- const current = getRuntimeContext(contextStorage);
188
- const context = makeRuntimeContext(resolver, scope, current?.resolutionPath ?? [], current?.signal, current);
189
- return runRuntimeContext(contextStorage, context, () => ScopeRuntime.run(scope, async () => {
190
- const resolutionPath = current?.resolutionPath ?? [provider.service];
191
- try {
192
- const instance = provider.release ? await scope.acquire(() => provider.acquire(), async (resource, outcome) => {
193
- try {
194
- await provider.release(resource, outcome);
195
- notifyRuntimeObservers(observers, (observer) => observer.onResourceRelease, {
196
- service: provider.service,
197
- outcome
198
- });
199
- } catch (cause) {
200
- notifyRuntimeObservers(observers, (observer) => observer.onResourceRelease, {
201
- service: provider.service,
202
- outcome,
203
- error: cause
204
- });
205
- throw cause;
206
- }
207
- }) : await provider.acquire();
208
- notifyRuntimeObservers(observers, (observer) => observer.onServiceAcquire, {
209
- service: provider.service,
210
- resolutionPath,
211
- outcome: SCOPE_SUCCESS
212
- });
213
- return instance;
214
- } catch (cause) {
215
- notifyRuntimeObservers(observers, (observer) => observer.onServiceAcquire, {
216
- service: provider.service,
217
- resolutionPath,
218
- outcome: {
219
- status: "failure",
220
- cause
221
- }
222
- });
223
- throw cause;
224
- }
225
- }, contextStorage));
226
- }
227
- });
228
- /** Resolve request-local providers first, then fall back to the Runtime root. */
229
- var ExecutionLayerBackend = class {
230
- local;
231
- root;
232
- localTags = /* @__PURE__ */ new Set();
233
- constructor(local, root) {
234
- this.local = local;
235
- this.root = root;
236
- }
237
- register(registration) {
238
- this.localTags.add(registration.service.serviceTag);
239
- this.local.register(registration);
240
- }
241
- async resolve(token) {
242
- if (this.localTags.has(token.serviceTag)) return await this.local.resolve(token);
243
- return await this.root.resolve(token);
244
- }
245
- async disposeAll() {
246
- await this.local.disposeAll();
247
- this.localTags.clear();
248
- }
249
- };
250
- var RuntimeHandleImpl = class {
251
- backend;
252
- resolver;
253
- rootScope;
254
- onCleanupFailure;
255
- contextStorage;
256
- signal;
257
- observers;
258
- services;
259
- disposePromise;
260
- warmupPromise;
261
- executions = /* @__PURE__ */ new Set();
262
- shutdownController = new AbortController();
263
- state = "active";
264
- constructor(backend, resolver, rootScope, onCleanupFailure, contextStorage, signal, observers, services) {
265
- this.backend = backend;
266
- this.resolver = resolver;
267
- this.rootScope = rootScope;
268
- this.onCleanupFailure = onCleanupFailure;
269
- this.contextStorage = contextStorage;
270
- this.signal = signal;
271
- this.observers = observers;
272
- this.services = services;
273
- }
274
- run(program, options) {
275
- this.assertActive();
276
- const executionScope = this.rootScope.fork();
277
- const signalLink = linkAbortSignals(this.signal, options?.signal, this.shutdownController.signal);
278
- return this.startExecution(signalLink, () => this.runExecution(executionScope, program, this.resolver, signalLink.signal));
279
- }
280
- runWith(layer, program, options) {
281
- this.assertActive();
282
- const executionScope = this.rootScope.fork();
283
- const localBackend = new MapLayerBackend();
284
- const backend = new ExecutionLayerBackend(localBackend, this.backend);
285
- const resolver = createResolutionResolver(backend, this.contextStorage, this.observers);
286
- const signalLink = linkAbortSignals(this.signal, options?.signal, this.shutdownController.signal);
287
- return this.startExecution(signalLink, async () => {
288
- try {
289
- return await this.runExecution(executionScope, async () => {
290
- for (const provider of layer.providers) backend.register(bindProviderToScope(provider, executionScope, this.contextStorage, resolver, this.observers));
291
- return await program();
292
- }, resolver, signalLink.signal);
293
- } finally {
294
- await localBackend.disposeAll();
295
- }
296
- });
297
- }
298
- warmup() {
299
- this.assertActive();
300
- if (this.warmupPromise) return this.warmupPromise;
301
- const warmup = runRuntimeContext(this.contextStorage, makeRuntimeContext(this.resolver, this.rootScope, [], this.signal), async () => {
302
- for (const service of this.services) await this.resolver.resolve(service);
303
- });
304
- this.warmupPromise = warmup;
305
- warmup.then(() => {
306
- if (this.warmupPromise === warmup) this.warmupPromise = void 0;
307
- }, () => {
308
- if (this.warmupPromise === warmup) this.warmupPromise = void 0;
309
- });
310
- return warmup;
311
- }
312
- startExecution(signalLink, run) {
313
- let resolveExecution;
314
- let rejectExecution;
315
- const execution = new Promise((resolve, reject) => {
316
- resolveExecution = resolve;
317
- rejectExecution = reject;
318
- });
319
- const activeExecution = { promise: execution };
320
- this.executions.add(activeExecution);
321
- execution.then(() => {
322
- this.executions.delete(activeExecution);
323
- signalLink.dispose();
324
- }, () => {
325
- this.executions.delete(activeExecution);
326
- signalLink.dispose();
327
- });
328
- try {
329
- run().then((value) => {
330
- resolveExecution(value);
331
- }, (cause) => {
332
- rejectExecution(cause);
333
- });
334
- } catch (cause) {
335
- rejectExecution(cause);
336
- }
337
- return execution;
338
- }
339
- runExecution(executionScope, program, resolver = this.resolver, signal = this.shutdownController.signal) {
340
- let outcome;
341
- const onOutcome = (determinedOutcome) => {
342
- outcome = determinedOutcome;
343
- };
344
- const runOptions = this.onCleanupFailure ? {
345
- classify: classifyRuntimeOutcome,
346
- onOutcome,
347
- onCleanupFailure: this.onCleanupFailure
348
- } : {
349
- classify: classifyRuntimeOutcome,
350
- onOutcome
351
- };
352
- notifyRuntimeObservers(this.observers, (observer) => observer.onExecutionStart, { scope: executionScope });
353
- return runScoped(executionScope, program, {
354
- ...runOptions,
355
- contextStorage: this.contextStorage,
356
- context: makeRuntimeContext(resolver, executionScope, [], signal)
357
- }).then((value) => {
358
- notifyRuntimeObservers(this.observers, (observer) => observer.onExecutionEnd, {
359
- scope: executionScope,
360
- outcome
361
- });
362
- return value;
363
- }, (cause) => {
364
- notifyRuntimeObservers(this.observers, (observer) => observer.onExecutionEnd, {
365
- scope: executionScope,
366
- outcome
367
- });
368
- throw cause;
369
- });
370
- }
371
- dispose(input) {
372
- if (this.disposePromise) return this.disposePromise;
373
- const outcome = isScopeOutcome(input) || input === void 0 ? input ?? SCOPE_SUCCESS : SCOPE_SUCCESS;
374
- const options = isScopeOutcome(input) || input === void 0 ? {} : input;
375
- validateDisposeOptions(options);
376
- this.state = "disposing";
377
- const executions = [...this.executions];
378
- this.disposePromise = this.performDispose(executions, outcome, options);
379
- return this.disposePromise;
380
- }
381
- async performDispose(executions, outcome, options) {
382
- const failures = [];
383
- await Promise.allSettled(this.warmupPromise ? [this.warmupPromise] : []);
384
- await this.waitForExecutions(executions, options);
385
- try {
386
- const signalLink = linkAbortSignals(this.signal, this.shutdownController.signal);
387
- try {
388
- await runRuntimeContext(this.contextStorage, makeRuntimeContext(this.resolver, this.rootScope, [], signalLink.signal), () => this.rootScope.close(outcome));
389
- } finally {
390
- signalLink.dispose();
391
- }
392
- } catch (cause) {
393
- failures.push(cause);
394
- }
395
- try {
396
- await this.backend.disposeAll();
397
- } catch (cause) {
398
- failures.push(cause);
399
- }
400
- this.state = "disposed";
401
- if (failures.length > 0) {
402
- const error = new LayerDisposeError(failures.flatMap(normalizeDisposeCauses));
403
- await notifyShutdownFailure(this.onCleanupFailure, {
404
- outcome,
405
- error
406
- });
407
- throw error;
408
- }
409
- }
410
- async waitForExecutions(executions, options) {
411
- const settled = Promise.allSettled(executions.map((execution) => execution.promise));
412
- if (options.abortAfterGracePeriod !== true || executions.length === 0) {
413
- await settled;
414
- return;
415
- }
416
- const gracePeriod = options.gracePeriod ?? 0;
417
- let timer;
418
- const timedOut = await Promise.race([settled.then(() => false), new Promise((resolve) => {
419
- timer = setTimeout(() => resolve(true), gracePeriod);
420
- })]);
421
- if (timer !== void 0) clearTimeout(timer);
422
- if (timedOut && !this.shutdownController.signal.aborted) this.shutdownController.abort(/* @__PURE__ */ new Error("Runtime shutdown grace period exceeded"));
423
- await settled;
424
- }
425
- assertActive() {
426
- if (this.state !== "active") throw new RuntimeHandleDisposedError();
427
- }
428
- };
429
- /** Build a Runtime handle for a complete Layer and register its providers. */
430
- const createRuntimeHandle = async (layer, backend, options = {}) => {
431
- const rootScope = Scope.make();
432
- const contextStorage = options.contextStorage ?? defaultRuntimeContextStorage;
433
- const observers = options.observers ?? [];
434
- const resolver = createResolutionResolver(backend, contextStorage, observers);
435
- ScopeRuntime.bind(rootScope, contextStorage);
436
- let current;
437
- try {
438
- for (const provider of layer.providers) {
439
- current = provider;
440
- await backend.register(bindProviderToScope(provider, rootScope, contextStorage, resolver, observers));
441
- }
442
- } catch (registrationCause) {
443
- const outcome = {
444
- status: "failure",
445
- cause: registrationCause
446
- };
447
- const cleanupCauses = [];
448
- try {
449
- await runRuntimeContext(contextStorage, makeRuntimeContext(resolver, rootScope, [], options.signal), () => rootScope.close(outcome));
450
- } catch (cause) {
451
- cleanupCauses.push(cause);
452
- }
453
- try {
454
- await backend.disposeAll();
455
- } catch (cause) {
456
- cleanupCauses.push(cause);
457
- }
458
- if (cleanupCauses.length > 0) {
459
- const shutdownError = new LayerDisposeError(cleanupCauses.flatMap(normalizeDisposeCauses));
460
- await notifyShutdownFailure(options.onCleanupFailure, {
461
- outcome,
462
- error: shutdownError
463
- });
464
- }
465
- const cleanupCause = cleanupCauses.length === 1 ? cleanupCauses[0] : cleanupCauses.length > 1 ? new LayerDisposeError(cleanupCauses.flatMap(normalizeDisposeCauses)) : void 0;
466
- throw new LayerRegistrationError(current?.service, registrationCause, cleanupCause);
467
- }
468
- return new RuntimeHandleImpl(backend, resolver, rootScope, options.onCleanupFailure, contextStorage, options.signal, observers, layer.providers.map((provider) => provider.service));
469
- };
470
- //#endregion
471
- //#region src/runtime/runtime.ts
472
- const isLayerBackend = (value) => value !== void 0 && "register" in value && "resolve" in value && "disposeAll" in value;
473
- const resolveRuntimeConfig = (backendOrOptions, legacyOptions) => {
474
- if (isLayerBackend(backendOrOptions)) return {
475
- backend: backendOrOptions,
476
- options: legacyOptions ?? {}
477
- };
478
- const options = backendOrOptions ?? {};
479
- return {
480
- backend: options.backend ?? new MapLayerBackend(),
481
- options
482
- };
483
- };
484
- /**
485
- * Long-lived execution environment backed by a complete Layer.
486
- *
487
- * A Runtime owns Layer resources until `dispose()` is called. Each `run()` is
488
- * isolated in a child Scope, while Layer-scoped resources remain shared.
489
- *
490
- * @example
491
- * ```ts
492
- * const runtime = await Runtime.make(AppLive)
493
- * const result = await runtime.run(loadUser('u1'))
494
- * await runtime.dispose()
495
- * ```
496
- *
497
- * @typeParam Provided The branded Service instances supplied by the Layer.
498
- */
499
- var Runtime = class Runtime {
500
- handle;
501
- constructor(handle) {
502
- this.handle = handle;
503
- }
504
- static async make(layer, backendOrOptions, legacyOptions) {
505
- const { backend, options } = resolveRuntimeConfig(backendOrOptions, legacyOptions);
506
- const handle = await createRuntimeHandle(layer, backend, options);
507
- const runtime = new Runtime(handle);
508
- if (options.warmup) await runtime.warmup();
509
- return runtime;
510
- }
511
- static async run(layer, backendOrProgramOrOptions, programOrOptions, legacyOptions) {
512
- let program;
513
- let backendOrOptions;
514
- let options;
515
- if (typeof backendOrProgramOrOptions === "function") {
516
- program = backendOrProgramOrOptions;
517
- backendOrOptions = programOrOptions;
518
- options = void 0;
519
- } else {
520
- backendOrOptions = backendOrProgramOrOptions;
521
- program = programOrOptions;
522
- options = legacyOptions;
523
- }
524
- const config = resolveRuntimeConfig(backendOrOptions, options);
525
- let programOutcome;
526
- const outcomeObserver = { onExecutionEnd: ({ outcome }) => {
527
- programOutcome = outcome;
528
- } };
529
- const runtimeOptions = {
530
- ...config.options,
531
- observers: [outcomeObserver, ...config.options.observers ?? []]
532
- };
533
- const runtime = await Runtime.make(layer, config.backend, runtimeOptions);
534
- let value;
535
- let executionFailed = false;
536
- let executionFailure;
537
- try {
538
- value = await runtime.runUnchecked(program);
539
- } catch (cause) {
540
- executionFailed = true;
541
- executionFailure = cause;
542
- }
543
- const outcome = programOutcome ?? {
544
- status: "failure",
545
- cause: executionFailure
546
- };
547
- try {
548
- await runtime.disposeWithOutcome(outcome);
549
- } catch (shutdownFailure) {
550
- if (!executionFailed && outcome.status === "success") throw shutdownFailure;
551
- }
552
- if (executionFailed) throw executionFailure;
553
- return value;
554
- }
555
- static async use(layer, use, options) {
556
- const runtime = await Runtime.make(layer, options);
557
- let value;
558
- let executionFailed = false;
559
- let executionFailure;
560
- let programOutcome;
561
- try {
562
- value = await use(runtime);
563
- programOutcome = classifyRuntimeOutcome(value);
564
- } catch (cause) {
565
- executionFailed = true;
566
- executionFailure = cause;
567
- programOutcome = {
568
- status: "failure",
569
- cause
570
- };
571
- }
572
- const outcome = programOutcome ?? {
573
- status: "failure",
574
- cause: executionFailure
575
- };
576
- try {
577
- await runtime.disposeWithOutcome(outcome);
578
- } catch (shutdownFailure) {
579
- if (!executionFailed && outcome.status === "success") throw shutdownFailure;
580
- }
581
- if (executionFailed) throw executionFailure;
582
- return value;
583
- }
584
- /** Resolve every Layer provider and dispose the Runtime if warmup fails. */
585
- async warmup() {
586
- try {
587
- await this.handle.warmup();
588
- } catch (cause) {
589
- try {
590
- await this.handle.dispose({
591
- status: "failure",
592
- cause
593
- });
594
- } catch {}
595
- throw cause;
596
- }
597
- }
598
- /** Run one execution in this Runtime's child Scope. */
599
- run(program, options) {
600
- return this.handle.run(program, options);
601
- }
602
- /** Run one execution with a Layer owned by that execution's child Scope. */
603
- runWith(layer, program, options) {
604
- return this.handle.runWith(layer, program, options);
605
- }
606
- runUnchecked(program) {
607
- return this.handle.run(program);
608
- }
609
- dispose(optionsOrOutcome) {
610
- return this.handle.dispose(optionsOrOutcome);
611
- }
612
- /** Release Runtime-owned resources through JavaScript's async disposal protocol. */
613
- async [Symbol.asyncDispose]() {
614
- await this.dispose();
615
- }
616
- disposeWithOutcome(outcome) {
617
- return this.handle.dispose(outcome);
618
- }
619
- };
620
- //#endregion
621
- export { CircularDependencyError, CurrentAbortSignal, DuplicateServiceError, Effect, Layer, LayerDisposeError, LayerGeneratorYieldError, LayerRegistrationError, MapLayerBackend, Program, Resource, ResourceNotDisposableError, ResourceReleaseFailure, Runtime, RuntimeContextNotConfiguredError, Scope, ScopeCloseError, ScopeClosedError, ScopeRuntimeNotConfiguredError, Service, ServiceAcquisitionError, ServiceNotFoundError, ServiceRuntime, ServiceRuntimeNotConfiguredError, ServiceTagCollisionError, pipe };
90
+ export { CircularDependencyError, CurrentAbortSignal, DuplicateServiceError, Effect, Layer, LayerDisposeError, LayerGeneratorYieldError, LayerRegistrationError, MapLayerBackend, Program, Resource, ResourceNotDisposableError, ResourceReleaseFailure, Runtime, RuntimeContextNotConfiguredError, RuntimeObserver, Scope, ScopeCloseError, ScopeClosedError, ScopeRuntimeNotConfiguredError, Service, ServiceAcquisitionError, ServiceNotFoundError, ServiceRuntime, ServiceRuntimeNotConfiguredError, ServiceTagCollisionError, pipe };
622
91
 
623
92
  //# sourceMappingURL=index.mjs.map