effect 3.4.5 → 3.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/Micro.js CHANGED
@@ -30,33 +30,33 @@ export const runSymbol = /*#__PURE__*/Symbol.for("effect/Micro/runSymbol");
30
30
  */
31
31
  export const isMicro = u => typeof u === "object" && u !== null && TypeId in u;
32
32
  // ----------------------------------------------------------------------------
33
- // Failures
33
+ // MicroCause
34
34
  // ----------------------------------------------------------------------------
35
35
  /**
36
- * @since 3.4.0
36
+ * @since 3.4.6
37
37
  * @experimental
38
- * @category failure
38
+ * @category MicroCause
39
39
  */
40
- export const FailureTypeId = /*#__PURE__*/Symbol.for("effect/Micro/Failure");
41
- const failureVariance = {
40
+ export const MicroCauseTypeId = /*#__PURE__*/Symbol.for("effect/Micro/MicroCause");
41
+ const microCauseVariance = {
42
42
  _E: identity
43
43
  };
44
- class FailureImpl extends globalThis.Error {
44
+ class MicroCauseImpl extends globalThis.Error {
45
45
  _tag;
46
46
  traces;
47
- [FailureTypeId];
47
+ [MicroCauseTypeId];
48
48
  constructor(_tag, originalError, traces) {
49
- const failureName = `Failure${_tag}`;
49
+ const causeName = `MicroCause.${_tag}`;
50
50
  let name;
51
51
  let message;
52
52
  let stack;
53
53
  if (originalError instanceof globalThis.Error) {
54
- name = `(${failureName}) ${originalError.name}`;
54
+ name = `(${causeName}) ${originalError.name}`;
55
55
  message = originalError.message;
56
56
  const messageLines = message.split("\n").length;
57
- stack = originalError.stack ? `(${failureName}) ${originalError.stack.split("\n").slice(0, messageLines + 3).join("\n")}` : `${name}: ${message}`;
57
+ stack = originalError.stack ? `(${causeName}) ${originalError.stack.split("\n").slice(0, messageLines + 3).join("\n")}` : `${name}: ${message}`;
58
58
  } else {
59
- name = failureName;
59
+ name = causeName;
60
60
  message = toStringUnknown(originalError, 0);
61
61
  stack = `${name}: ${message}`;
62
62
  }
@@ -66,7 +66,7 @@ class FailureImpl extends globalThis.Error {
66
66
  super(message);
67
67
  this._tag = _tag;
68
68
  this.traces = traces;
69
- this[FailureTypeId] = failureVariance;
69
+ this[MicroCauseTypeId] = microCauseVariance;
70
70
  this.name = name;
71
71
  this.stack = stack;
72
72
  }
@@ -80,146 +80,149 @@ class FailureImpl extends globalThis.Error {
80
80
  return this.stack;
81
81
  }
82
82
  }
83
- class FailureExpectedImpl extends FailureImpl {
83
+ class FailImpl extends MicroCauseImpl {
84
84
  error;
85
85
  constructor(error, traces = []) {
86
- super("Expected", error, traces);
86
+ super("Fail", error, traces);
87
87
  this.error = error;
88
88
  }
89
89
  }
90
90
  /**
91
- * @since 3.4.0
91
+ * @since 3.4.6
92
92
  * @experimental
93
- * @category failure
93
+ * @category MicroCause
94
94
  */
95
- export const FailureExpected = (error, traces = []) => new FailureExpectedImpl(error, traces);
96
- class FailureUnexpectedImpl extends FailureImpl {
95
+ export const causeFail = (error, traces = []) => new FailImpl(error, traces);
96
+ class DieImpl extends MicroCauseImpl {
97
97
  defect;
98
98
  constructor(defect, traces = []) {
99
- super("Unexpected", defect, traces);
99
+ super("Die", defect, traces);
100
100
  this.defect = defect;
101
101
  }
102
102
  }
103
103
  /**
104
- * @since 3.4.0
104
+ * @since 3.4.6
105
105
  * @experimental
106
- * @category failure
106
+ * @category MicroCause
107
107
  */
108
- export const FailureUnexpected = (defect, traces = []) => new FailureUnexpectedImpl(defect, traces);
109
- class FailureAbortedImpl extends FailureImpl {
108
+ export const causeDie = (defect, traces = []) => new DieImpl(defect, traces);
109
+ class InterruptImpl extends MicroCauseImpl {
110
110
  constructor(traces = []) {
111
- super("Aborted", "aborted", traces);
111
+ super("Interrupt", "interrupted", traces);
112
112
  }
113
113
  }
114
114
  /**
115
- * @since 3.4.0
115
+ * @since 3.4.6
116
116
  * @experimental
117
- * @category failure
117
+ * @category MicroCause
118
118
  */
119
- export const FailureAborted = (traces = []) => new FailureAbortedImpl(traces);
119
+ export const causeInterrupt = (traces = []) => new InterruptImpl(traces);
120
120
  /**
121
- * @since 3.4.0
121
+ * @since 3.4.6
122
122
  * @experimental
123
- * @category failure
123
+ * @category MicroCause
124
124
  */
125
- export const failureIsExpected = self => self._tag === "Expected";
125
+ export const causeIsFail = self => self._tag === "Fail";
126
126
  /**
127
- * @since 3.4.0
127
+ * @since 3.4.6
128
128
  * @experimental
129
- * @category failure
129
+ * @category MicroCause
130
130
  */
131
- export const failureIsUnexpected = self => self._tag === "Unexpected";
131
+ export const causeIsDie = self => self._tag === "Die";
132
132
  /**
133
- * @since 3.4.0
133
+ * @since 3.4.6
134
134
  * @experimental
135
- * @category failure
135
+ * @category MicroCause
136
136
  */
137
- export const failureIsAborted = self => self._tag === "Aborted";
137
+ export const causeIsInterrupt = self => self._tag === "Interrupt";
138
138
  /**
139
- * @since 3.4.0
139
+ * @since 3.4.6
140
140
  * @experimental
141
- * @category failure
141
+ * @category MicroCause
142
142
  */
143
- export const failureSquash = self => self._tag === "Expected" ? self.error : self._tag === "Unexpected" ? self.defect : self;
143
+ export const causeSquash = self => self._tag === "Fail" ? self.error : self._tag === "Die" ? self.defect : self;
144
144
  /**
145
- * @since 3.4.0
145
+ * @since 3.4.6
146
146
  * @experimental
147
- * @category failure
147
+ * @category MicroCause
148
148
  */
149
- export const failureWithTrace = /*#__PURE__*/dual(2, (self, trace) => {
150
- if (self._tag === "Expected") {
151
- return FailureExpected(self.error, [...self.traces, trace]);
152
- } else if (self._tag === "Unexpected") {
153
- return FailureUnexpected(self.defect, [...self.traces, trace]);
149
+ export const causeWithTrace = /*#__PURE__*/dual(2, (self, trace) => {
150
+ const traces = [...self.traces, trace];
151
+ switch (self._tag) {
152
+ case "Die":
153
+ return causeDie(self.defect, traces);
154
+ case "Interrupt":
155
+ return causeInterrupt(traces);
156
+ case "Fail":
157
+ return causeFail(self.error, traces);
154
158
  }
155
- return FailureAborted([...self.traces, trace]);
156
159
  });
157
160
  /**
158
- * @since 3.4.0
161
+ * @since 3.4.6
159
162
  * @experimental
160
- * @category result
163
+ * @category MicroExit
161
164
  */
162
- export const ResultAborted = /*#__PURE__*/Either.left( /*#__PURE__*/FailureAborted());
165
+ export const exitInterrupt = /*#__PURE__*/Either.left( /*#__PURE__*/causeInterrupt());
163
166
  /**
164
- * @since 3.4.0
167
+ * @since 3.4.6
165
168
  * @experimental
166
- * @category result
169
+ * @category MicroExit
167
170
  */
168
- export const ResultSuccess = Either.right;
171
+ export const exitSucceed = Either.right;
169
172
  /**
170
- * @since 3.4.0
173
+ * @since 3.4.6
171
174
  * @experimental
172
- * @category result
175
+ * @category MicroExit
173
176
  */
174
- export const ResultFail = e => Either.left(FailureExpected(e));
177
+ export const exitFail = e => Either.left(causeFail(e));
175
178
  /**
176
- * @since 3.4.0
179
+ * @since 3.4.6
177
180
  * @experimental
178
- * @category result
181
+ * @category MicroExit
179
182
  */
180
- export const ResultFailUnexpected = defect => Either.left(FailureUnexpected(defect));
183
+ export const exitDie = defect => Either.left(causeDie(defect));
181
184
  /**
182
- * @since 3.4.0
185
+ * @since 3.4.6
183
186
  * @experimental
184
- * @category result
187
+ * @category MicroExit
185
188
  */
186
- export const ResultFailWith = Either.left;
189
+ export const exitFailCause = Either.left;
187
190
  /**
188
- * @since 3.4.0
191
+ * @since 3.4.6
189
192
  * @experimental
190
- * @category result
193
+ * @category MicroExit
191
194
  */
192
- export const resultIsSuccess = Either.isRight;
195
+ export const exitIsSuccess = Either.isRight;
193
196
  /**
194
- * @since 3.4.0
197
+ * @since 3.4.6
195
198
  * @experimental
196
- * @category result
199
+ * @category MicroExit
197
200
  */
198
- export const resultIsFailure = Either.isLeft;
201
+ export const exitIsFailure = Either.isLeft;
199
202
  /**
200
- * @since 3.4.0
203
+ * @since 3.4.6
201
204
  * @experimental
202
- * @category result
205
+ * @category MicroExit
203
206
  */
204
- export const resultIsAborted = self => resultIsFailure(self) && self.left._tag === "Aborted";
207
+ export const exitIsInterrupt = self => exitIsFailure(self) && self.left._tag === "Interrupt";
205
208
  /**
206
- * @since 3.4.0
209
+ * @since 3.4.6
207
210
  * @experimental
208
- * @category result
211
+ * @category MicroExit
209
212
  */
210
- export const resultIsFailureExpected = self => resultIsFailure(self) && self.left._tag === "Expected";
213
+ export const exitIsFail = self => exitIsFailure(self) && self.left._tag === "Fail";
211
214
  /**
212
- * @since 3.4.0
215
+ * @since 3.4.6
213
216
  * @experimental
214
- * @category result
217
+ * @category MicroExit
215
218
  */
216
- export const resultIsFailureUnexpected = self => resultIsFailure(self) && self.left._tag === "Unexpected";
219
+ export const exitIsDie = self => exitIsFailure(self) && self.left._tag === "Die";
217
220
  /**
218
- * @since 3.4.0
221
+ * @since 3.4.6
219
222
  * @experimental
220
- * @category result
223
+ * @category MicroExit
221
224
  */
222
- export const resultVoid = /*#__PURE__*/ResultSuccess(void 0);
225
+ export const exitVoid = /*#__PURE__*/exitSucceed(void 0);
223
226
  // ----------------------------------------------------------------------------
224
227
  // env
225
228
  // ----------------------------------------------------------------------------
@@ -294,8 +297,8 @@ export const envMutate = /*#__PURE__*/dual(2, (self, f) => envMake(f(Object.assi
294
297
  * @experimental
295
298
  * @category environment
296
299
  */
297
- export const service = tag => make(function (env, onResult) {
298
- onResult(ResultSuccess(Context.get(envGet(env, currentContext), tag)));
300
+ export const service = tag => make(function (env, onExit) {
301
+ onExit(exitSucceed(Context.get(envGet(env, currentContext), tag)));
299
302
  });
300
303
  /**
301
304
  * Access the given `Context.Tag` from the environment, without tracking the
@@ -308,8 +311,8 @@ export const service = tag => make(function (env, onResult) {
308
311
  * @experimental
309
312
  * @category environment
310
313
  */
311
- export const serviceOption = tag => make(function (env, onResult) {
312
- onResult(ResultSuccess(Context.getOption(envGet(env, currentContext), tag)));
314
+ export const serviceOption = tag => make(function (env, onExit) {
315
+ onExit(exitSucceed(Context.getOption(envGet(env, currentContext), tag)));
313
316
  });
314
317
  /**
315
318
  * Retrieve the current value of the given `EnvRef`.
@@ -318,7 +321,7 @@ export const serviceOption = tag => make(function (env, onResult) {
318
321
  * @experimental
319
322
  * @category environment
320
323
  */
321
- export const getEnvRef = envRef => make((env, onResult) => onResult(Either.right(envGet(env, envRef))));
324
+ export const getEnvRef = envRef => make((env, onExit) => onExit(Either.right(envGet(env, envRef))));
322
325
  /**
323
326
  * Set the value of the given `EnvRef` for the duration of the effect.
324
327
  *
@@ -326,7 +329,7 @@ export const getEnvRef = envRef => make((env, onResult) => onResult(Either.right
326
329
  * @experimental
327
330
  * @category environment
328
331
  */
329
- export const locally = /*#__PURE__*/dual(3, (self, fiberRef, value) => make((env, onResult) => self[runSymbol](envSet(env, fiberRef, value), onResult)));
332
+ export const locally = /*#__PURE__*/dual(3, (self, fiberRef, value) => make((env, onExit) => self[runSymbol](envSet(env, fiberRef, value), onExit)));
330
333
  /**
331
334
  * Access the current `Context` from the environment.
332
335
  *
@@ -342,10 +345,10 @@ export const context = () => getEnvRef(currentContext);
342
345
  * @experimental
343
346
  * @category environment
344
347
  */
345
- export const provideContext = /*#__PURE__*/dual(2, (self, provided) => make(function (env, onResult) {
348
+ export const provideContext = /*#__PURE__*/dual(2, (self, provided) => make(function (env, onExit) {
346
349
  const context = envGet(env, currentContext);
347
350
  const nextEnv = envSet(env, currentContext, Context.merge(context, provided));
348
- self[runSymbol](nextEnv, onResult);
351
+ self[runSymbol](nextEnv, onExit);
349
352
  }));
350
353
  /**
351
354
  * Add the provided service to the current context.
@@ -354,20 +357,20 @@ export const provideContext = /*#__PURE__*/dual(2, (self, provided) => make(func
354
357
  * @experimental
355
358
  * @category environment
356
359
  */
357
- export const provideService = /*#__PURE__*/dual(3, (self, tag, service) => make(function (env, onResult) {
360
+ export const provideService = /*#__PURE__*/dual(3, (self, tag, service) => make(function (env, onExit) {
358
361
  const context = envGet(env, currentContext);
359
362
  const nextEnv = envSet(env, currentContext, Context.add(context, tag, service));
360
- self[runSymbol](nextEnv, onResult);
363
+ self[runSymbol](nextEnv, onExit);
361
364
  }));
362
365
  /**
363
366
  * Create a service using the provided `Micro` effect, and add it to the
364
367
  * current context.
365
368
  *
366
- * @since 3.4.0
369
+ * @since 3.4.6
367
370
  * @experimental
368
371
  * @category environment
369
372
  */
370
- export const provideServiceMicro = /*#__PURE__*/dual(3, (self, tag, acquire) => flatMap(acquire, service => provideService(self, tag, service)));
373
+ export const provideServiceEffect = /*#__PURE__*/dual(3, (self, tag, acquire) => flatMap(acquire, service => provideService(self, tag, service)));
371
374
  // ========================================================================
372
375
  // Env refs
373
376
  // ========================================================================
@@ -457,21 +460,21 @@ const unsafeMake = run => {
457
460
  self[runSymbol] = run;
458
461
  return self;
459
462
  };
460
- const unsafeMakeOptions = (run, checkAbort) => unsafeMake(function execute(env, onResult) {
463
+ const unsafeMakeOptions = (run, checkAbort) => unsafeMake(function execute(env, onExit) {
461
464
  if (checkAbort && env.refs[currentInterruptible.key] !== false && env.refs[currentAbortSignal.key].aborted) {
462
- return onResult(ResultAborted);
465
+ return onExit(exitInterrupt);
463
466
  }
464
467
  microDepthState.depth++;
465
468
  if (microDepthState.depth === 1) {
466
469
  microDepthState.maxDepthBeforeYield = envGet(env, currentMaxDepthBeforeYield);
467
470
  }
468
471
  if (microDepthState.depth >= microDepthState.maxDepthBeforeYield) {
469
- yieldAdd(() => execute(env, onResult));
472
+ yieldAdd(() => execute(env, onExit));
470
473
  } else {
471
474
  try {
472
- run(env, onResult);
475
+ run(env, onExit);
473
476
  } catch (err) {
474
- onResult(ResultFailUnexpected(err));
477
+ onExit(exitDie(err));
475
478
  }
476
479
  }
477
480
  microDepthState.depth--;
@@ -487,24 +490,24 @@ const unsafeMakeOptions = (run, checkAbort) => unsafeMake(function execute(env,
487
490
  */
488
491
  export const make = run => unsafeMakeOptions(run, true);
489
492
  /**
490
- * Converts a `Result` into a `Micro` effect.
493
+ * Converts a `MicroExit` into a `Micro` effect.
491
494
  *
492
- * @since 3.4.0
495
+ * @since 3.4.6
493
496
  * @experimental
494
497
  * @category constructors
495
498
  */
496
- export const fromResult = self => make(function (_env, onResult) {
497
- onResult(self);
499
+ export const fromExit = self => make(function (_env, onExit) {
500
+ onExit(self);
498
501
  });
499
502
  /**
500
- * Converts a lazy `Result` into a `Micro` effect.
503
+ * Converts a lazy `MicroExit` into a `Micro` effect.
501
504
  *
502
- * @since 3.4.0
505
+ * @since 3.4.6
503
506
  * @experimental
504
507
  * @category constructors
505
508
  */
506
- export const fromResultSync = self => make(function (_env, onResult) {
507
- onResult(self());
509
+ export const fromExitSync = self => make(function (_env, onExit) {
510
+ onExit(self());
508
511
  });
509
512
  /**
510
513
  * Creates a `Micro` effect that will succeed with the specified constant value.
@@ -513,7 +516,7 @@ export const fromResultSync = self => make(function (_env, onResult) {
513
516
  * @experimental
514
517
  * @category constructors
515
518
  */
516
- export const succeed = a => fromResult(ResultSuccess(a));
519
+ export const succeed = a => fromExit(exitSucceed(a));
517
520
  /**
518
521
  * Creates a `Micro` effect that will succeed with `Option.Some` of the value.
519
522
  *
@@ -533,66 +536,66 @@ export const succeedNone = /*#__PURE__*/succeed( /*#__PURE__*/Option.none());
533
536
  /**
534
537
  * Creates a `Micro` effect that will fail with the specified error.
535
538
  *
536
- * This will result in a `FailureExpected`, where the error is tracked at the
539
+ * This will result in a `CauseFail`, where the error is tracked at the
537
540
  * type level.
538
541
  *
539
542
  * @since 3.4.0
540
543
  * @experimental
541
544
  * @category constructors
542
545
  */
543
- export const fail = e => fromResult(ResultFail(e));
546
+ export const fail = e => fromExit(exitFail(e));
544
547
  /**
545
548
  * Creates a `Micro` effect that will fail with the lazily evaluated error.
546
549
  *
547
- * This will result in a `FailureExpected`, where the error is tracked at the
550
+ * This will result in a `CauseFail`, where the error is tracked at the
548
551
  * type level.
549
552
  *
550
553
  * @since 3.4.0
551
554
  * @experimental
552
555
  * @category constructors
553
556
  */
554
- export const failSync = e => make(function (_env, onResult) {
555
- onResult(ResultFail(e()));
557
+ export const failSync = e => make(function (_env, onExit) {
558
+ onExit(exitFail(e()));
556
559
  });
557
560
  /**
558
561
  * Creates a `Micro` effect that will die with the specified error.
559
562
  *
560
- * This will result in a `FailureUnexpected`, where the error is not tracked at
563
+ * This will result in a `CauseDie`, where the error is not tracked at
561
564
  * the type level.
562
565
  *
563
566
  * @since 3.4.0
564
567
  * @experimental
565
568
  * @category constructors
566
569
  */
567
- export const die = defect => fromResult(ResultFailUnexpected(defect));
570
+ export const die = defect => fromExit(exitDie(defect));
568
571
  /**
569
- * Creates a `Micro` effect that will fail with the specified `Failure`.
572
+ * Creates a `Micro` effect that will fail with the specified `MicroCause`.
570
573
  *
571
- * @since 3.4.0
574
+ * @since 3.4.6
572
575
  * @experimental
573
576
  * @category constructors
574
577
  */
575
- export const failWith = failure => fromResult(ResultFailWith(failure));
578
+ export const failCause = cause => fromExit(exitFailCause(cause));
576
579
  /**
577
- * Creates a `Micro` effect that will fail with the lazily evaluated `Failure`.
580
+ * Creates a `Micro` effect that will fail with the lazily evaluated `MicroCause`.
578
581
  *
579
- * @since 3.4.0
582
+ * @since 3.4.6
580
583
  * @experimental
581
584
  * @category constructors
582
585
  */
583
- export const failWithSync = failure => fromResultSync(() => ResultFailWith(failure()));
586
+ export const failCauseSync = cause => fromExitSync(() => exitFailCause(cause()));
584
587
  /**
585
588
  * Creates a `Micro` effect that will succeed with the lazily evaluated value.
586
589
  *
587
590
  * If the evaluation of the value throws an error, the effect will fail with
588
- * `FailureUnexpected`.
591
+ * `CauseDie`.
589
592
  *
590
593
  * @since 3.4.0
591
594
  * @experimental
592
595
  * @category constructors
593
596
  */
594
- export const sync = evaluate => make(function (_env, onResult) {
595
- onResult(ResultSuccess(evaluate()));
597
+ export const sync = evaluate => make(function (_env, onExit) {
598
+ onExit(exitSucceed(evaluate()));
596
599
  });
597
600
  /**
598
601
  * Converts an `Option` into a `Micro` effect, that will fail with
@@ -603,8 +606,8 @@ export const sync = evaluate => make(function (_env, onResult) {
603
606
  * @experimental
604
607
  * @category constructors
605
608
  */
606
- export const fromOption = option => make(function (_env, onResult) {
607
- onResult(option._tag === "Some" ? ResultSuccess(option.value) : ResultFail(new NoSuchElementException({})));
609
+ export const fromOption = option => make(function (_env, onExit) {
610
+ onExit(option._tag === "Some" ? exitSucceed(option.value) : exitFail(new NoSuchElementException({})));
608
611
  });
609
612
  /**
610
613
  * Converts an `Either` into a `Micro` effect, that will fail with the left side
@@ -615,8 +618,8 @@ export const fromOption = option => make(function (_env, onResult) {
615
618
  * @experimental
616
619
  * @category constructors
617
620
  */
618
- export const fromEither = either => make(function (_env, onResult) {
619
- onResult(either._tag === "Right" ? either : ResultFail(either.left));
621
+ export const fromEither = either => make(function (_env, onExit) {
622
+ onExit(either._tag === "Right" ? either : exitFail(either.left));
620
623
  });
621
624
  /**
622
625
  * Lazily creates a `Micro` effect from the given side-effect.
@@ -625,8 +628,8 @@ export const fromEither = either => make(function (_env, onResult) {
625
628
  * @experimental
626
629
  * @category constructors
627
630
  */
628
- export const suspend = evaluate => make(function (env, onResult) {
629
- evaluate()[runSymbol](env, onResult);
631
+ export const suspend = evaluate => make(function (env, onExit) {
632
+ evaluate()[runSymbol](env, onExit);
630
633
  });
631
634
  const void_ = /*#__PURE__*/succeed(void 0);
632
635
  export {
@@ -649,16 +652,16 @@ void_ as void };
649
652
  * @experimental
650
653
  * @category constructors
651
654
  */
652
- export const async = register => make(function (env, onResult) {
655
+ export const async = register => make(function (env, onExit) {
653
656
  let resumed = false;
654
657
  const controller = register.length > 1 ? new AbortController() : undefined;
655
658
  const signal = envGet(env, currentAbortSignal);
656
659
  let cleanup = undefined;
657
660
  function onAbort() {
658
661
  if (cleanup) {
659
- resume(uninterruptible(andThen(cleanup, fromResult(ResultAborted))));
662
+ resume(uninterruptible(andThen(cleanup, fromExit(exitInterrupt))));
660
663
  } else {
661
- resume(fromResult(ResultAborted));
664
+ resume(fromExit(exitInterrupt));
662
665
  }
663
666
  if (controller !== undefined) {
664
667
  controller.abort();
@@ -670,17 +673,17 @@ export const async = register => make(function (env, onResult) {
670
673
  }
671
674
  resumed = true;
672
675
  signal.removeEventListener("abort", onAbort);
673
- effect[runSymbol](env, onResult);
676
+ effect[runSymbol](env, onExit);
674
677
  }
675
678
  cleanup = controller === undefined ? register(resume) : register(resume, controller.signal);
676
679
  if (resumed) return;
677
680
  signal.addEventListener("abort", onAbort);
678
681
  });
679
- const try_ = options => make(function (_env, onResult) {
682
+ const try_ = options => make(function (_env, onExit) {
680
683
  try {
681
- onResult(ResultSuccess(options.try()));
684
+ onExit(exitSucceed(options.try()));
682
685
  } catch (err) {
683
- onResult(ResultFail(options.catch(err)));
686
+ onExit(exitFail(options.catch(err)));
684
687
  }
685
688
  });
686
689
  export {
@@ -702,7 +705,7 @@ export {
702
705
  try_ as try };
703
706
  /**
704
707
  * Wrap a `Promise` into a `Micro` effect. Any errors will result in a
705
- * `FailureUnexpected`.
708
+ * `CauseDie`.
706
709
  *
707
710
  * @since 3.4.0
708
711
  * @experimental
@@ -763,8 +766,8 @@ const yieldAdd = task => {
763
766
  * @experimental
764
767
  * @category constructors
765
768
  */
766
- export const yieldNow = /*#__PURE__*/make(function (_env, onResult) {
767
- yieldAdd(() => onResult(resultVoid));
769
+ export const yieldNow = /*#__PURE__*/make(function (_env, onExit) {
770
+ yieldAdd(() => onExit(exitVoid));
768
771
  });
769
772
  /**
770
773
  * Flush any yielded effects that are waiting to be executed.
@@ -795,7 +798,7 @@ export const never = /*#__PURE__*/async(function () {
795
798
  * @experimental
796
799
  * @category constructors
797
800
  */
798
- export const gen = (...args) => make(function (env, onResult) {
801
+ export const gen = (...args) => make(function (env, onExit) {
799
802
  const iterator = args.length === 1 ? args[0]() : args[1].call(args[0]);
800
803
  let running = false;
801
804
  let value = undefined;
@@ -806,21 +809,21 @@ export const gen = (...args) => make(function (env, onResult) {
806
809
  while (shouldContinue) {
807
810
  const result = iterator.next(value);
808
811
  if (result.done) {
809
- return onResult(ResultSuccess(result.value));
812
+ return onExit(exitSucceed(result.value));
810
813
  }
811
814
  shouldContinue = false;
812
- yieldWrapGet(result.value)[runSymbol](env, function (result) {
813
- if (result._tag === "Left") {
814
- onResult(result);
815
+ yieldWrapGet(result.value)[runSymbol](env, function (exit) {
816
+ if (exit._tag === "Left") {
817
+ onExit(exit);
815
818
  } else {
816
819
  shouldContinue = true;
817
- value = result.right;
820
+ value = exit.right;
818
821
  if (!running) run();
819
822
  }
820
823
  });
821
824
  }
822
825
  } catch (err) {
823
- onResult(ResultFailUnexpected(err));
826
+ onExit(exitDie(err));
824
827
  }
825
828
  running = false;
826
829
  }
@@ -836,8 +839,8 @@ export const gen = (...args) => make(function (env, onResult) {
836
839
  * @experimental
837
840
  * @category mapping & sequencing
838
841
  */
839
- export const flatten = self => make(function (env, onResult) {
840
- self[runSymbol](env, result => result._tag === "Left" ? onResult(result) : result.right[runSymbol](env, onResult));
842
+ export const flatten = self => make(function (env, onExit) {
843
+ self[runSymbol](env, exit => exit._tag === "Left" ? onExit(exit) : exit.right[runSymbol](env, onExit));
841
844
  });
842
845
  /**
843
846
  * Transforms the success value of the `Micro` effect with the specified
@@ -847,9 +850,9 @@ export const flatten = self => make(function (env, onResult) {
847
850
  * @experimental
848
851
  * @category mapping & sequencing
849
852
  */
850
- export const map = /*#__PURE__*/dual(2, (self, f) => make(function (env, onResult) {
851
- self[runSymbol](env, function (result) {
852
- onResult(result._tag === "Left" ? result : ResultSuccess(f(result.right)));
853
+ export const map = /*#__PURE__*/dual(2, (self, f) => make(function (env, onExit) {
854
+ self[runSymbol](env, function (exit) {
855
+ onExit(exit._tag === "Left" ? exit : exitSucceed(f(exit.right)));
853
856
  });
854
857
  }));
855
858
  /**
@@ -877,12 +880,12 @@ export const asSome = self => map(self, Option.some);
877
880
  * @experimental
878
881
  * @category mapping & sequencing
879
882
  */
880
- export const flatMap = /*#__PURE__*/dual(2, (self, f) => make(function (env, onResult) {
881
- self[runSymbol](env, function (result) {
882
- if (result._tag === "Left") {
883
- return onResult(result);
883
+ export const flatMap = /*#__PURE__*/dual(2, (self, f) => make(function (env, onExit) {
884
+ self[runSymbol](env, function (exit) {
885
+ if (exit._tag === "Left") {
886
+ return onExit(exit);
884
887
  }
885
- f(result.right)[runSymbol](env, onResult);
888
+ f(exit.right)[runSymbol](env, onExit);
886
889
  });
887
890
  }));
888
891
  /**
@@ -892,7 +895,7 @@ export const flatMap = /*#__PURE__*/dual(2, (self, f) => make(function (env, onR
892
895
  * @experimental
893
896
  * @category mapping & sequencing
894
897
  */
895
- export const flip = self => matchMicro(self, {
898
+ export const flip = self => matchEffect(self, {
896
899
  onFailure: succeed,
897
900
  onSuccess: fail
898
901
  });
@@ -907,18 +910,18 @@ export const flip = self => matchMicro(self, {
907
910
  * @experimental
908
911
  * @category mapping & sequencing
909
912
  */
910
- export const andThen = /*#__PURE__*/dual(2, (self, f) => make(function (env, onResult) {
911
- self[runSymbol](env, function (result) {
912
- if (result._tag === "Left") {
913
- return onResult(result);
913
+ export const andThen = /*#__PURE__*/dual(2, (self, f) => make(function (env, onExit) {
914
+ self[runSymbol](env, function (exit) {
915
+ if (exit._tag === "Left") {
916
+ return onExit(exit);
914
917
  } else if (envGet(env, currentAbortSignal).aborted) {
915
- return onResult(ResultAborted);
918
+ return onExit(exitInterrupt);
916
919
  }
917
- const value = isMicro(f) ? f : typeof f === "function" ? f(result.right) : f;
920
+ const value = isMicro(f) ? f : typeof f === "function" ? f(exit.right) : f;
918
921
  if (isMicro(value)) {
919
- value[runSymbol](env, onResult);
922
+ value[runSymbol](env, onExit);
920
923
  } else {
921
- onResult(ResultSuccess(value));
924
+ onExit(exitSucceed(value));
922
925
  }
923
926
  });
924
927
  }));
@@ -931,23 +934,23 @@ export const andThen = /*#__PURE__*/dual(2, (self, f) => make(function (env, onR
931
934
  * @experimental
932
935
  * @category mapping & sequencing
933
936
  */
934
- export const tap = /*#__PURE__*/dual(2, (self, f) => make(function (env, onResult) {
935
- self[runSymbol](env, function (selfResult) {
936
- if (selfResult._tag === "Left") {
937
- return onResult(selfResult);
937
+ export const tap = /*#__PURE__*/dual(2, (self, f) => make(function (env, onExit) {
938
+ self[runSymbol](env, function (selfExit) {
939
+ if (selfExit._tag === "Left") {
940
+ return onExit(selfExit);
938
941
  } else if (envGet(env, currentAbortSignal).aborted) {
939
- return onResult(ResultAborted);
942
+ return onExit(exitInterrupt);
940
943
  }
941
- const value = isMicro(f) ? f : typeof f === "function" ? f(selfResult.right) : f;
944
+ const value = isMicro(f) ? f : typeof f === "function" ? f(selfExit.right) : f;
942
945
  if (isMicro(value)) {
943
- value[runSymbol](env, function (tapResult) {
944
- if (tapResult._tag === "Left") {
945
- return onResult(tapResult);
946
+ value[runSymbol](env, function (tapExit) {
947
+ if (tapExit._tag === "Left") {
948
+ return onExit(tapExit);
946
949
  }
947
- onResult(selfResult);
950
+ onExit(selfExit);
948
951
  });
949
952
  } else {
950
- onResult(selfResult);
953
+ onExit(selfExit);
951
954
  }
952
955
  });
953
956
  }));
@@ -960,25 +963,25 @@ export const tap = /*#__PURE__*/dual(2, (self, f) => make(function (env, onResul
960
963
  */
961
964
  export const asVoid = self => map(self, _ => void 0);
962
965
  /**
963
- * Access the `Result` of the given `Micro` effect.
966
+ * Access the `MicroExit` of the given `Micro` effect.
964
967
  *
965
- * @since 3.4.0
968
+ * @since 3.4.6
966
969
  * @experimental
967
970
  * @category mapping & sequencing
968
971
  */
969
- export const asResult = self => make(function (env, onResult) {
970
- self[runSymbol](env, function (result) {
971
- onResult(ResultSuccess(result));
972
+ export const exit = self => make(function (env, onExit) {
973
+ self[runSymbol](env, function (exit) {
974
+ onExit(exitSucceed(exit));
972
975
  });
973
976
  });
974
977
  /**
975
- * Replace the error type of the given `Micro` with the full `Failure` object.
978
+ * Replace the error type of the given `Micro` with the full `MicroCause` object.
976
979
  *
977
980
  * @since 3.4.0
978
981
  * @experimental
979
982
  * @category mapping & sequencing
980
983
  */
981
- export const sandbox = self => catchFailure(self, failure => fail(failure));
984
+ export const sandbox = self => catchAllCause(self, cause => fail(cause));
982
985
  function forkSignal(env) {
983
986
  const controller = new AbortController();
984
987
  const parentSignal = envGet(env, currentAbortSignal);
@@ -1003,25 +1006,25 @@ function forkSignal(env) {
1003
1006
  * @experimental
1004
1007
  * @category sequencing
1005
1008
  */
1006
- export const raceAll = all => make(function (env, onResult) {
1009
+ export const raceAll = all => make(function (env, onExit) {
1007
1010
  const [envWithSignal, onAbort] = forkSignal(env);
1008
1011
  const effects = Array.from(all);
1009
1012
  let len = effects.length;
1010
1013
  let index = 0;
1011
1014
  let done = 0;
1012
- let result = undefined;
1013
- const failures = [];
1014
- function onDone(result_) {
1015
+ let exit = undefined;
1016
+ const causes = [];
1017
+ function onDone(exit_) {
1015
1018
  done++;
1016
- if (result_._tag === "Right" && result === undefined) {
1019
+ if (exit_._tag === "Right" && exit === undefined) {
1017
1020
  len = index;
1018
- result = result_;
1021
+ exit = exit_;
1019
1022
  onAbort();
1020
- } else if (result_._tag === "Left") {
1021
- failures.push(result_.left);
1023
+ } else if (exit_._tag === "Left") {
1024
+ causes.push(exit_.left);
1022
1025
  }
1023
1026
  if (done >= len) {
1024
- onResult(result ?? Either.left(failures[0]));
1027
+ onExit(exit ?? Either.left(causes[0]));
1025
1028
  }
1026
1029
  }
1027
1030
  for (; index < len; index++) {
@@ -1037,23 +1040,23 @@ export const raceAll = all => make(function (env, onResult) {
1037
1040
  * @experimental
1038
1041
  * @category sequencing
1039
1042
  */
1040
- export const raceAllFirst = all => make(function (env, onResult) {
1043
+ export const raceAllFirst = all => make(function (env, onExit) {
1041
1044
  const [envWithSignal, onAbort] = forkSignal(env);
1042
1045
  const effects = Array.from(all);
1043
1046
  let len = effects.length;
1044
1047
  let index = 0;
1045
1048
  let done = 0;
1046
- let result = undefined;
1047
- const failures = [];
1048
- function onDone(result_) {
1049
+ let exit = undefined;
1050
+ const causes = [];
1051
+ function onDone(exit_) {
1049
1052
  done++;
1050
- if (result === undefined) {
1053
+ if (exit === undefined) {
1051
1054
  len = index;
1052
- result = result_;
1055
+ exit = exit_;
1053
1056
  onAbort();
1054
1057
  }
1055
1058
  if (done >= len) {
1056
- onResult(result ?? Either.left(failures[0]));
1059
+ onExit(exit ?? Either.left(causes[0]));
1057
1060
  }
1058
1061
  }
1059
1062
  for (; index < len; index++) {
@@ -1113,7 +1116,7 @@ export const zipWith = /*#__PURE__*/dual(args => isMicro(args[1]), (self, that,
1113
1116
  // ----------------------------------------------------------------------------
1114
1117
  /**
1115
1118
  * Filter the specified effect with the provided function, failing with specified
1116
- * `Failure` if the predicate fails.
1119
+ * `MicroCause` if the predicate fails.
1117
1120
  *
1118
1121
  * In addition to the filtering capabilities discussed earlier, you have the option to further
1119
1122
  * refine and narrow down the type of the success channel by providing a
@@ -1122,7 +1125,7 @@ export const zipWith = /*#__PURE__*/dual(args => isMicro(args[1]), (self, that,
1122
1125
  * @experimental
1123
1126
  * @category filtering & conditionals
1124
1127
  */
1125
- export const filterOrFailWith = /*#__PURE__*/dual(args => isMicro(args[0]), (self, refinement, orFailWith) => flatMap(self, a => refinement(a) ? succeed(a) : failWith(orFailWith(a))));
1128
+ export const filterOrFailCause = /*#__PURE__*/dual(args => isMicro(args[0]), (self, refinement, orFailWith) => flatMap(self, a => refinement(a) ? succeed(a) : failCause(orFailWith(a))));
1126
1129
  /**
1127
1130
  * Filter the specified effect with the provided function, failing with specified
1128
1131
  * error if the predicate fails.
@@ -1150,34 +1153,34 @@ export const when = /*#__PURE__*/dual(2, (self, condition) => flatMap(isMicro(co
1150
1153
  * Repeat the given `Micro` using the provided options.
1151
1154
  *
1152
1155
  * The `while` predicate will be checked after each iteration, and can use the
1153
- * fall `Result` of the effect to determine if the repetition should continue.
1156
+ * fall `MicroExit` of the effect to determine if the repetition should continue.
1154
1157
  *
1155
- * @since 3.4.0
1158
+ * @since 3.4.6
1156
1159
  * @experimental
1157
1160
  * @category repetition
1158
1161
  */
1159
- export const repeatResult = /*#__PURE__*/dual(2, (self, options) => make(function (env, onResult) {
1160
- const startedAt = options.delay ? Date.now() : 0;
1162
+ export const repeatExit = /*#__PURE__*/dual(2, (self, options) => make(function (env, onExit) {
1163
+ const startedAt = options.schedule ? Date.now() : 0;
1161
1164
  let attempt = 0;
1162
- self[runSymbol](env, function loop(result) {
1163
- if (options.while !== undefined && !options.while(result)) {
1164
- return onResult(result);
1165
+ self[runSymbol](env, function loop(exit) {
1166
+ if (options.while !== undefined && !options.while(exit)) {
1167
+ return onExit(exit);
1165
1168
  } else if (options.times !== undefined && attempt >= options.times) {
1166
- return onResult(result);
1169
+ return onExit(exit);
1167
1170
  }
1168
1171
  attempt++;
1169
1172
  let delayEffect = yieldNow;
1170
- if (options.delay !== undefined) {
1173
+ if (options.schedule !== undefined) {
1171
1174
  const elapsed = Date.now() - startedAt;
1172
- const duration = options.delay(attempt, elapsed);
1175
+ const duration = options.schedule(attempt, elapsed);
1173
1176
  if (Option.isNone(duration)) {
1174
- return onResult(result);
1177
+ return onExit(exit);
1175
1178
  }
1176
1179
  delayEffect = sleep(duration.value);
1177
1180
  }
1178
- delayEffect[runSymbol](env, function (result) {
1179
- if (result._tag === "Left") {
1180
- return onResult(result);
1181
+ delayEffect[runSymbol](env, function (exit) {
1182
+ if (exit._tag === "Left") {
1183
+ return onExit(exit);
1181
1184
  }
1182
1185
  self[runSymbol](env, loop);
1183
1186
  });
@@ -1191,9 +1194,9 @@ export const repeatResult = /*#__PURE__*/dual(2, (self, options) => make(functio
1191
1194
  * @experimental
1192
1195
  * @category repetition
1193
1196
  */
1194
- export const repeat = /*#__PURE__*/dual(args => isMicro(args[0]), (self, options) => repeatResult(self, {
1197
+ export const repeat = /*#__PURE__*/dual(args => isMicro(args[0]), (self, options) => repeatExit(self, {
1195
1198
  ...options,
1196
- while: result => result._tag === "Right" && (options?.while === undefined || options.while(result.right))
1199
+ while: exit => exit._tag === "Right" && (options?.while === undefined || options.while(exit.right))
1197
1200
  }));
1198
1201
  /**
1199
1202
  * Repeat the given `Micro` effect forever, only stopping if the effect fails.
@@ -1204,127 +1207,155 @@ export const repeat = /*#__PURE__*/dual(args => isMicro(args[0]), (self, options
1204
1207
  */
1205
1208
  export const forever = self => repeat(self);
1206
1209
  /**
1207
- * Create a `DelayFn` that will generate a duration with an exponential backoff.
1210
+ * Create a `MicroSchedule` that will stop repeating after the specified number
1211
+ * of attempts.
1208
1212
  *
1209
- * @since 3.4.0
1213
+ * @since 3.4.6
1210
1214
  * @experimental
1211
- * @category delay fn
1215
+ * @category scheduling
1212
1216
  */
1213
- export const delayExponential = (baseMillis, factor = 2) => attempt => Option.some(attempt ** factor * baseMillis);
1217
+ export const scheduleRecurs = n => attempt => attempt <= n ? Option.some(0) : Option.none();
1214
1218
  /**
1215
- * Create a `DelayFn` that will generate a duration with fixed intervals.
1219
+ * Create a `MicroSchedule` that will generate a constant delay.
1216
1220
  *
1217
- * @since 3.4.0
1221
+ * @since 3.4.6
1218
1222
  * @experimental
1219
- * @category delay fn
1223
+ * @category scheduling
1220
1224
  */
1221
- export const delaySpaced = millis => _ => Option.some(millis);
1225
+ export const scheduleSpaced = millis => () => Option.some(millis);
1222
1226
  /**
1223
- * Transform a `DelayFn` to one that will have a duration that will never exceed
1227
+ * Create a `MicroSchedule` that will generate a delay with an exponential backoff.
1228
+ *
1229
+ * @since 3.4.6
1230
+ * @experimental
1231
+ * @category scheduling
1232
+ */
1233
+ export const scheduleExponential = (baseMillis, factor = 2) => attempt => Option.some(Math.pow(factor, attempt) * baseMillis);
1234
+ /**
1235
+ * Returns a new `MicroSchedule` with an added calculated delay to each delay
1236
+ * returned by this schedule.
1237
+ *
1238
+ * @since 3.4.6
1239
+ * @experimental
1240
+ * @category scheduling
1241
+ */
1242
+ export const scheduleAddDelay = /*#__PURE__*/dual(2, (self, f) => (attempt, elapsed) => Option.map(self(attempt, elapsed), duration => duration + f()));
1243
+ /**
1244
+ * Transform a `MicroSchedule` to one that will have a delay that will never exceed
1224
1245
  * the specified maximum.
1225
1246
  *
1226
- * @since 3.4.0
1247
+ * @since 3.4.6
1227
1248
  * @experimental
1228
- * @category delay fn
1249
+ * @category scheduling
1229
1250
  */
1230
- export const delayWithMax = /*#__PURE__*/dual(2, (self, max) => (attempt, elapsed) => Option.map(self(attempt, elapsed), duration => Math.min(duration, max)));
1251
+ export const scheduleWithMaxDelay = /*#__PURE__*/dual(2, (self, max) => (attempt, elapsed) => Option.map(self(attempt, elapsed), duration => Math.min(duration, max)));
1231
1252
  /**
1232
- * Transform a `DelayFn` to one that will stop repeating after the specified
1253
+ * Transform a `MicroSchedule` to one that will stop repeating after the specified
1233
1254
  * amount of time.
1234
1255
  *
1235
- * @since 3.4.0
1256
+ * @since 3.4.6
1236
1257
  * @experimental
1237
- * @category delay fn
1258
+ * @category scheduling
1238
1259
  */
1239
- export const delayWithMaxElapsed = /*#__PURE__*/dual(2, (self, max) => (attempt, elapsed) => elapsed < max ? self(attempt, elapsed) : Option.none());
1260
+ export const scheduleWithMaxElapsed = /*#__PURE__*/dual(2, (self, max) => (attempt, elapsed) => elapsed < max ? self(attempt, elapsed) : Option.none());
1240
1261
  /**
1241
- * Transform a `DelayFn` to one that will stop repeating after the specified
1242
- * number of attempts.
1262
+ * Combines two `MicroSchedule`s, by recurring if either schedule wants to
1263
+ * recur, using the minimum of the two durations between recurrences.
1243
1264
  *
1244
- * @since 3.4.0
1265
+ * @since 3.4.6
1245
1266
  * @experimental
1246
- * @category delay fn
1267
+ * @category scheduling
1247
1268
  */
1248
- export const delayWithRecurs = /*#__PURE__*/dual(2, (self, n) => (attempt, elapsed) => Option.filter(self(attempt, elapsed), () => attempt <= n));
1269
+ export const scheduleUnion = /*#__PURE__*/dual(2, (self, that) => (attempt, elapsed) => Option.zipWith(self(attempt, elapsed), that(attempt, elapsed), (d1, d2) => Math.min(d1, d2)));
1270
+ /**
1271
+ * Combines two `MicroSchedule`s, by recurring only if both schedules want to
1272
+ * recur, using the maximum of the two durations between recurrences.
1273
+ *
1274
+ * @since 3.4.6
1275
+ * @experimental
1276
+ * @category scheduling
1277
+ */
1278
+ export const scheduleIntersect = /*#__PURE__*/dual(2, (self, that) => (attempt, elapsed) => Option.zipWith(self(attempt, elapsed), that(attempt, elapsed), (d1, d2) => Math.max(d1, d2)));
1249
1279
  // ----------------------------------------------------------------------------
1250
1280
  // error handling
1251
1281
  // ----------------------------------------------------------------------------
1252
1282
  /**
1253
- * Catch the full `Failure` object of the given `Micro` effect, allowing you to
1254
- * recover from any kind of failure.
1283
+ * Catch the full `MicroCause` object of the given `Micro` effect, allowing you to
1284
+ * recover from any kind of cause.
1255
1285
  *
1256
- * @since 3.4.0
1286
+ * @since 3.4.6
1257
1287
  * @experimental
1258
1288
  * @category error handling
1259
1289
  */
1260
- export const catchFailure = /*#__PURE__*/dual(2, (self, f) => catchFailureIf(self, constTrue, f));
1290
+ export const catchAllCause = /*#__PURE__*/dual(2, (self, f) => catchCauseIf(self, constTrue, f));
1261
1291
  /**
1262
- * Selectively catch a `Failure` object of the given `Micro` effect,
1292
+ * Selectively catch a `MicroCause` object of the given `Micro` effect,
1263
1293
  * using the provided predicate to determine if the failure should be caught.
1264
1294
  *
1265
- * @since 3.4.0
1295
+ * @since 3.4.6
1266
1296
  * @experimental
1267
1297
  * @category error handling
1268
1298
  */
1269
- export const catchFailureIf = /*#__PURE__*/dual(3, (self, refinement, f) => make(function (env, onResult) {
1270
- self[runSymbol](env, function (result) {
1271
- if (result._tag === "Right" || !refinement(result.left)) {
1272
- return onResult(result);
1299
+ export const catchCauseIf = /*#__PURE__*/dual(3, (self, predicate, f) => make(function (env, onExit) {
1300
+ self[runSymbol](env, function (exit) {
1301
+ if (exit._tag === "Right" || !predicate(exit.left)) {
1302
+ onExit(exit);
1303
+ } else {
1304
+ f(exit.left)[runSymbol](env, onExit);
1273
1305
  }
1274
- f(result.left)[runSymbol](env, onResult);
1275
1306
  });
1276
1307
  }));
1277
1308
  /**
1278
1309
  * Catch the error of the given `Micro` effect, allowing you to recover from it.
1279
1310
  *
1280
- * It only catches expected (`FailureExpected`) errors.
1311
+ * It only catches expected (`MicroCause.Fail`) errors.
1281
1312
  *
1282
- * @since 3.4.0
1313
+ * @since 3.4.6
1283
1314
  * @experimental
1284
1315
  * @category error handling
1285
1316
  */
1286
- export const catchExpected = /*#__PURE__*/dual(2, (self, f) => catchFailureIf(self, failureIsExpected, failure => f(failure.error)));
1317
+ export const catchAll = /*#__PURE__*/dual(2, (self, f) => catchAllCause(self, cause => causeIsFail(cause) ? f(cause.error) : failCause(cause)));
1287
1318
  /**
1288
1319
  * Catch any unexpected errors of the given `Micro` effect, allowing you to recover from them.
1289
1320
  *
1290
- * @since 3.4.0
1321
+ * @since 3.4.6
1291
1322
  * @experimental
1292
1323
  * @category error handling
1293
1324
  */
1294
- export const catchUnexpected = /*#__PURE__*/dual(2, (self, f) => catchFailureIf(self, failureIsUnexpected, failure => f(failure.defect)));
1325
+ export const catchAllDefect = /*#__PURE__*/dual(2, (self, f) => catchCauseIf(self, causeIsDie, die => f(die.defect)));
1295
1326
  /**
1296
- * Perform a side effect using the full `Failure` object of the given `Micro`.
1327
+ * Perform a side effect using the full `MicroCause` object of the given `Micro`.
1297
1328
  *
1298
- * @since 3.4.0
1329
+ * @since 3.4.6
1299
1330
  * @experimental
1300
1331
  * @category error handling
1301
1332
  */
1302
- export const tapFailure = /*#__PURE__*/dual(2, (self, f) => tapFailureIf(self, constTrue, f));
1333
+ export const tapErrorCause = /*#__PURE__*/dual(2, (self, f) => tapErrorCauseIf(self, constTrue, f));
1303
1334
  /**
1304
- * Perform a side effect using if a `Failure` object matches the specified
1335
+ * Perform a side effect using if a `MicroCause` object matches the specified
1305
1336
  * predicate.
1306
1337
  *
1307
1338
  * @since 3.4.0
1308
1339
  * @experimental
1309
1340
  * @category error handling
1310
1341
  */
1311
- export const tapFailureIf = /*#__PURE__*/dual(3, (self, refinement, f) => catchFailureIf(self, refinement, failure => andThen(f(failure), failWith(failure))));
1342
+ export const tapErrorCauseIf = /*#__PURE__*/dual(3, (self, refinement, f) => catchCauseIf(self, refinement, cause => andThen(f(cause), failCause(cause))));
1312
1343
  /**
1313
1344
  * Perform a side effect from expected errors of the given `Micro`.
1314
1345
  *
1315
- * @since 3.4.0
1346
+ * @since 3.4.6
1316
1347
  * @experimental
1317
1348
  * @category error handling
1318
1349
  */
1319
- export const tapExpected = /*#__PURE__*/dual(2, (self, f) => tapFailureIf(self, failureIsExpected, failure => f(failure.error)));
1350
+ export const tapError = /*#__PURE__*/dual(2, (self, f) => tapErrorCauseIf(self, causeIsFail, fail => f(fail.error)));
1320
1351
  /**
1321
1352
  * Perform a side effect from unexpected errors of the given `Micro`.
1322
1353
  *
1323
- * @since 3.4.0
1354
+ * @since 3.4.6
1324
1355
  * @experimental
1325
1356
  * @category error handling
1326
1357
  */
1327
- export const tapUnexpected = /*#__PURE__*/dual(2, (self, f) => tapFailureIf(self, failureIsUnexpected, failure => f(failure.defect)));
1358
+ export const tapDefect = /*#__PURE__*/dual(2, (self, f) => tapErrorCauseIf(self, causeIsDie, die => f(die.defect)));
1328
1359
  /**
1329
1360
  * Catch any expected errors that match the specified predicate.
1330
1361
  *
@@ -1332,7 +1363,7 @@ export const tapUnexpected = /*#__PURE__*/dual(2, (self, f) => tapFailureIf(self
1332
1363
  * @experimental
1333
1364
  * @category error handling
1334
1365
  */
1335
- export const catchIf = /*#__PURE__*/dual(3, (self, predicate, f) => catchFailureIf(self, f => failureIsExpected(f) && predicate(f.error), failure => f(failure.error)));
1366
+ export const catchIf = /*#__PURE__*/dual(3, (self, predicate, f) => catchCauseIf(self, f => causeIsFail(f) && predicate(f.error), fail => f(fail.error)));
1336
1367
  /**
1337
1368
  * Recovers from the specified tagged error.
1338
1369
  *
@@ -1342,13 +1373,13 @@ export const catchIf = /*#__PURE__*/dual(3, (self, predicate, f) => catchFailure
1342
1373
  */
1343
1374
  export const catchTag = /*#__PURE__*/dual(3, (self, k, f) => catchIf(self, isTagged(k), f));
1344
1375
  /**
1345
- * Transform the full `Failure` object of the given `Micro` effect.
1376
+ * Transform the full `MicroCause` object of the given `Micro` effect.
1346
1377
  *
1347
- * @since 3.4.0
1378
+ * @since 3.4.6
1348
1379
  * @experimental
1349
1380
  * @category error handling
1350
1381
  */
1351
- export const mapFailure = /*#__PURE__*/dual(2, (self, f) => catchFailure(self, failure => failWith(f(failure))));
1382
+ export const mapErrorCause = /*#__PURE__*/dual(2, (self, f) => catchAllCause(self, cause => failCause(f(cause))));
1352
1383
  /**
1353
1384
  * Transform any expected errors of the given `Micro` effect.
1354
1385
  *
@@ -1356,7 +1387,7 @@ export const mapFailure = /*#__PURE__*/dual(2, (self, f) => catchFailure(self, f
1356
1387
  * @experimental
1357
1388
  * @category error handling
1358
1389
  */
1359
- export const mapError = /*#__PURE__*/dual(2, (self, f) => catchExpected(self, error => fail(f(error))));
1390
+ export const mapError = /*#__PURE__*/dual(2, (self, f) => catchAll(self, error => fail(f(error))));
1360
1391
  /**
1361
1392
  * Elevate any expected errors of the given `Micro` effect to unexpected errors,
1362
1393
  * resulting in an error type of `never`.
@@ -1365,7 +1396,7 @@ export const mapError = /*#__PURE__*/dual(2, (self, f) => catchExpected(self, er
1365
1396
  * @experimental
1366
1397
  * @category error handling
1367
1398
  */
1368
- export const orDie = self => catchExpected(self, die);
1399
+ export const orDie = self => catchAll(self, die);
1369
1400
  /**
1370
1401
  * Recover from all errors by succeeding with the given value.
1371
1402
  *
@@ -1373,7 +1404,7 @@ export const orDie = self => catchExpected(self, die);
1373
1404
  * @experimental
1374
1405
  * @category error handling
1375
1406
  */
1376
- export const orElseSucceed = /*#__PURE__*/dual(2, (self, f) => catchExpected(self, _ => sync(f)));
1407
+ export const orElseSucceed = /*#__PURE__*/dual(2, (self, f) => catchAll(self, _ => sync(f)));
1377
1408
  /**
1378
1409
  * Ignore any expected errors of the given `Micro` effect, returning `void`.
1379
1410
  *
@@ -1381,7 +1412,7 @@ export const orElseSucceed = /*#__PURE__*/dual(2, (self, f) => catchExpected(sel
1381
1412
  * @experimental
1382
1413
  * @category error handling
1383
1414
  */
1384
- export const ignore = self => matchMicro(self, {
1415
+ export const ignore = self => matchEffect(self, {
1385
1416
  onFailure: _ => void_,
1386
1417
  onSuccess: _ => void_
1387
1418
  });
@@ -1392,8 +1423,8 @@ export const ignore = self => matchMicro(self, {
1392
1423
  * @experimental
1393
1424
  * @category error handling
1394
1425
  */
1395
- export const ignoreLogged = self => matchMicro(self, {
1396
- onFailure: failure => sync(() => console.error(failure)),
1426
+ export const ignoreLogged = self => matchEffect(self, {
1427
+ onFailure: error => sync(() => console.error(error)),
1397
1428
  onSuccess: _ => void_
1398
1429
  });
1399
1430
  /**
@@ -1429,13 +1460,13 @@ export const either = self => match(self, {
1429
1460
  * @experimental
1430
1461
  * @category error handling
1431
1462
  */
1432
- export const retry = /*#__PURE__*/dual(args => isMicro(args[0]), (self, options) => repeatResult(self, {
1463
+ export const retry = /*#__PURE__*/dual(args => isMicro(args[0]), (self, options) => repeatExit(self, {
1433
1464
  ...options,
1434
- while: result => result._tag === "Left" && result.left._tag === "Expected" && (options?.while === undefined || options.while(result.left.error))
1465
+ while: exit => exit._tag === "Left" && exit.left._tag === "Fail" && (options?.while === undefined || options.while(exit.left.error))
1435
1466
  }));
1436
1467
  /**
1437
1468
  * Add a stack trace to any failures that occur in the effect. The trace will be
1438
- * added to the `traces` field of the `Failure` object.
1469
+ * added to the `traces` field of the `MicroCause` object.
1439
1470
  *
1440
1471
  * @since 3.4.0
1441
1472
  * @experimental
@@ -1446,21 +1477,21 @@ export const withTrace = function () {
1446
1477
  globalThis.Error.stackTraceLimit = 2;
1447
1478
  const error = new globalThis.Error();
1448
1479
  globalThis.Error.stackTraceLimit = prevLimit;
1449
- function generate(name, failure) {
1480
+ function generate(name, cause) {
1450
1481
  const stack = error.stack;
1451
1482
  if (!stack) {
1452
- return failure;
1483
+ return cause;
1453
1484
  }
1454
1485
  const line = stack.split("\n")[2]?.trim().replace(/^at /, "");
1455
1486
  if (!line) {
1456
- return failure;
1487
+ return cause;
1457
1488
  }
1458
1489
  const lineMatch = line.match(/\((.*)\)$/);
1459
- return failureWithTrace(failure, `at ${name} (${lineMatch ? lineMatch[1] : line})`);
1490
+ return causeWithTrace(cause, `at ${name} (${lineMatch ? lineMatch[1] : line})`);
1460
1491
  }
1461
- const f = name => self => unsafeMakeOptions(function (env, onResult) {
1462
- self[runSymbol](env, function (result) {
1463
- onResult(result._tag === "Left" ? Either.left(generate(name, result.left)) : result);
1492
+ const f = name => self => unsafeMakeOptions(function (env, onExit) {
1493
+ self[runSymbol](env, function (exit) {
1494
+ onExit(exit._tag === "Left" ? Either.left(generate(name, exit.left)) : exit);
1464
1495
  });
1465
1496
  }, false);
1466
1497
  if (arguments.length === 2) {
@@ -1472,36 +1503,36 @@ export const withTrace = function () {
1472
1503
  // pattern matching
1473
1504
  // ----------------------------------------------------------------------------
1474
1505
  /**
1475
- * @since 3.4.0
1506
+ * @since 3.4.6
1476
1507
  * @experimental
1477
1508
  * @category pattern matching
1478
1509
  */
1479
- export const matchFailureMicro = /*#__PURE__*/dual(2, (self, options) => make(function (env, onResult) {
1480
- self[runSymbol](env, function (result) {
1510
+ export const matchCauseEffect = /*#__PURE__*/dual(2, (self, options) => make(function (env, onExit) {
1511
+ self[runSymbol](env, function (exit) {
1481
1512
  try {
1482
- const next = result._tag === "Left" ? options.onFailure(result.left) : options.onSuccess(result.right);
1483
- next[runSymbol](env, onResult);
1513
+ const next = exit._tag === "Left" ? options.onFailure(exit.left) : options.onSuccess(exit.right);
1514
+ next[runSymbol](env, onExit);
1484
1515
  } catch (err) {
1485
- onResult(ResultFailUnexpected(err));
1516
+ onExit(exitDie(err));
1486
1517
  }
1487
1518
  });
1488
1519
  }));
1489
1520
  /**
1490
- * @since 3.4.0
1521
+ * @since 3.4.6
1491
1522
  * @experimental
1492
1523
  * @category pattern matching
1493
1524
  */
1494
- export const matchFailure = /*#__PURE__*/dual(2, (self, options) => matchFailureMicro(self, {
1495
- onFailure: failure => sync(() => options.onFailure(failure)),
1525
+ export const matchCause = /*#__PURE__*/dual(2, (self, options) => matchCauseEffect(self, {
1526
+ onFailure: cause => sync(() => options.onFailure(cause)),
1496
1527
  onSuccess: value => sync(() => options.onSuccess(value))
1497
1528
  }));
1498
1529
  /**
1499
- * @since 3.4.0
1530
+ * @since 3.4.6
1500
1531
  * @experimental
1501
1532
  * @category pattern matching
1502
1533
  */
1503
- export const matchMicro = /*#__PURE__*/dual(2, (self, options) => matchFailureMicro(self, {
1504
- onFailure: failure => failure._tag === "Expected" ? options.onFailure(failure.error) : failWith(failure),
1534
+ export const matchEffect = /*#__PURE__*/dual(2, (self, options) => matchCauseEffect(self, {
1535
+ onFailure: cause => cause._tag === "Fail" ? options.onFailure(cause.error) : failCause(cause),
1505
1536
  onSuccess: options.onSuccess
1506
1537
  }));
1507
1538
  /**
@@ -1509,7 +1540,7 @@ export const matchMicro = /*#__PURE__*/dual(2, (self, options) => matchFailureMi
1509
1540
  * @experimental
1510
1541
  * @category pattern matching
1511
1542
  */
1512
- export const match = /*#__PURE__*/dual(2, (self, options) => matchMicro(self, {
1543
+ export const match = /*#__PURE__*/dual(2, (self, options) => matchEffect(self, {
1513
1544
  onFailure: error => sync(() => options.onFailure(error)),
1514
1545
  onSuccess: value => sync(() => options.onSuccess(value))
1515
1546
  }));
@@ -1551,6 +1582,21 @@ export const delay = /*#__PURE__*/dual(2, (self, millis) => andThen(sleep(millis
1551
1582
  * @category delays & timeouts
1552
1583
  */
1553
1584
  export const timeoutOrElse = /*#__PURE__*/dual(2, (self, options) => raceFirst(self, andThen(interruptible(sleep(options.duration)), options.onTimeout)));
1585
+ /**
1586
+ * Returns an effect that will timeout this effect, that will fail with a
1587
+ * `TimeoutException` if the timeout elapses before the effect has produced a
1588
+ * value.
1589
+ *
1590
+ * If the timeout elapses, the running effect will be safely interrupted.
1591
+ *
1592
+ * @since 3.4.0
1593
+ * @experimental
1594
+ * @category delays & timeouts
1595
+ */
1596
+ export const timeout = /*#__PURE__*/dual(2, (self, millis) => timeoutOrElse(self, {
1597
+ duration: millis,
1598
+ onTimeout: () => fail(new TimeoutException())
1599
+ }));
1554
1600
  /**
1555
1601
  * Returns an effect that will timeout this effect, succeeding with a `None`
1556
1602
  * if the timeout elapses before the effect has produced a value; and `Some` of
@@ -1562,7 +1608,7 @@ export const timeoutOrElse = /*#__PURE__*/dual(2, (self, options) => raceFirst(s
1562
1608
  * @experimental
1563
1609
  * @category delays & timeouts
1564
1610
  */
1565
- export const timeout = /*#__PURE__*/dual(2, (self, millis) => raceFirst(asSome(self), as(interruptible(sleep(millis)), Option.none())));
1611
+ export const timeoutOption = /*#__PURE__*/dual(2, (self, millis) => raceFirst(asSome(self), as(interruptible(sleep(millis)), Option.none())));
1566
1612
  // ----------------------------------------------------------------------------
1567
1613
  // resources & finalization
1568
1614
  // ----------------------------------------------------------------------------
@@ -1578,7 +1624,7 @@ export const MicroScopeTypeId = /*#__PURE__*/Symbol.for("effect/Micro/MicroScope
1578
1624
  * @category resources & finalization
1579
1625
  */
1580
1626
  export const MicroScope = /*#__PURE__*/Context.GenericTag("effect/Micro/MicroScope");
1581
- class ScopeImpl {
1627
+ class MicroScopeImpl {
1582
1628
  [MicroScopeTypeId];
1583
1629
  state = {
1584
1630
  _tag: "Open",
@@ -1598,7 +1644,7 @@ class ScopeImpl {
1598
1644
  this.state.finalizers.add(finalizer);
1599
1645
  return void_;
1600
1646
  }
1601
- return finalizer(this.state.result);
1647
+ return finalizer(this.state.exit);
1602
1648
  });
1603
1649
  }
1604
1650
  unsafeRemoveFinalizer(finalizer) {
@@ -1606,28 +1652,28 @@ class ScopeImpl {
1606
1652
  this.state.finalizers.delete(finalizer);
1607
1653
  }
1608
1654
  }
1609
- close(result) {
1655
+ close(microExit) {
1610
1656
  return suspend(() => {
1611
1657
  if (this.state._tag === "Open") {
1612
1658
  const finalizers = Array.from(this.state.finalizers).reverse();
1613
1659
  this.state = {
1614
1660
  _tag: "Closed",
1615
- result
1661
+ exit: microExit
1616
1662
  };
1617
- return flatMap(forEach(finalizers, finalizer => asResult(finalizer(result))), results => asVoid(fromResult(Either.all(results))));
1663
+ return flatMap(forEach(finalizers, finalizer => exit(finalizer(microExit))), exits => asVoid(fromExit(Either.all(exits))));
1618
1664
  }
1619
1665
  return void_;
1620
1666
  });
1621
1667
  }
1622
1668
  get fork() {
1623
1669
  return sync(() => {
1624
- const newScope = new ScopeImpl();
1670
+ const newScope = new MicroScopeImpl();
1625
1671
  if (this.state._tag === "Closed") {
1626
1672
  newScope.state = this.state;
1627
1673
  return newScope;
1628
1674
  }
1629
- function fin(result) {
1630
- return newScope.close(result);
1675
+ function fin(exit) {
1676
+ return newScope.close(exit);
1631
1677
  }
1632
1678
  this.state.finalizers.add(fin);
1633
1679
  newScope.unsafeAddFinalizer(_ => sync(() => this.unsafeRemoveFinalizer(fin)));
@@ -1640,13 +1686,13 @@ class ScopeImpl {
1640
1686
  * @experimental
1641
1687
  * @category resources & finalization
1642
1688
  */
1643
- export const scopeMake = /*#__PURE__*/sync(() => new ScopeImpl());
1689
+ export const scopeMake = /*#__PURE__*/sync(() => new MicroScopeImpl());
1644
1690
  /**
1645
1691
  * @since 3.4.0
1646
1692
  * @experimental
1647
1693
  * @category resources & finalization
1648
1694
  */
1649
- export const scopeUnsafeMake = () => new ScopeImpl();
1695
+ export const scopeUnsafeMake = () => new MicroScopeImpl();
1650
1696
  /**
1651
1697
  * Access the current `MicroScope`.
1652
1698
  *
@@ -1672,8 +1718,8 @@ export const provideScope = /*#__PURE__*/dual(2, (self, scope) => provideService
1672
1718
  * @category resources & finalization
1673
1719
  */
1674
1720
  export const scoped = self => suspend(function () {
1675
- const scope = new ScopeImpl();
1676
- return onResult(provideService(self, MicroScope, scope), result => scope.close(result));
1721
+ const scope = new MicroScopeImpl();
1722
+ return onExit(provideService(self, MicroScope, scope), exit => scope.close(exit));
1677
1723
  });
1678
1724
  /**
1679
1725
  * Create a resource with a cleanup `Micro` effect, ensuring the cleanup is
@@ -1683,7 +1729,7 @@ export const scoped = self => suspend(function () {
1683
1729
  * @experimental
1684
1730
  * @category resources & finalization
1685
1731
  */
1686
- export const acquireRelease = (acquire, release) => uninterruptible(flatMap(scope, scope => tap(acquire, a => scope.addFinalizer(result => release(a, result)))));
1732
+ export const acquireRelease = (acquire, release) => uninterruptible(flatMap(scope, scope => tap(acquire, a => scope.addFinalizer(exit => release(a, exit)))));
1687
1733
  /**
1688
1734
  * Add a finalizer to the current `MicroScope`.
1689
1735
  *
@@ -1694,31 +1740,31 @@ export const acquireRelease = (acquire, release) => uninterruptible(flatMap(scop
1694
1740
  export const addFinalizer = finalizer => flatMap(scope, scope => scope.addFinalizer(finalizer));
1695
1741
  /**
1696
1742
  * When the `Micro` effect is completed, run the given finalizer effect with the
1697
- * `Result` of the executed effect.
1743
+ * `MicroExit` of the executed effect.
1698
1744
  *
1699
- * @since 3.4.0
1745
+ * @since 3.4.6
1700
1746
  * @experimental
1701
1747
  * @category resources & finalization
1702
1748
  */
1703
- export const onResult = /*#__PURE__*/dual(2, (self, f) => onResultIf(self, constTrue, f));
1749
+ export const onExit = /*#__PURE__*/dual(2, (self, f) => onExitIf(self, constTrue, f));
1704
1750
  /**
1705
1751
  * When the `Micro` effect is completed, run the given finalizer effect if it
1706
1752
  * matches the specified predicate.
1707
1753
  *
1708
- * @since 3.4.0
1754
+ * @since 3.4.6
1709
1755
  * @experimental
1710
1756
  * @category resources & finalization
1711
1757
  */
1712
- export const onResultIf = /*#__PURE__*/dual(3, (self, refinement, f) => uninterruptibleMask(restore => make(function (env, onResult) {
1713
- restore(self)[runSymbol](env, function (result) {
1714
- if (!refinement(result)) {
1715
- return onResult(result);
1758
+ export const onExitIf = /*#__PURE__*/dual(3, (self, refinement, f) => uninterruptibleMask(restore => make(function (env, onExit) {
1759
+ restore(self)[runSymbol](env, function (exit) {
1760
+ if (!refinement(exit)) {
1761
+ return onExit(exit);
1716
1762
  }
1717
- f(result)[runSymbol](env, function (finalizerResult) {
1718
- if (finalizerResult._tag === "Left") {
1719
- return onResult(finalizerResult);
1763
+ f(exit)[runSymbol](env, function (finalizerExit) {
1764
+ if (finalizerExit._tag === "Left") {
1765
+ return onExit(finalizerExit);
1720
1766
  }
1721
- onResult(result);
1767
+ onExit(exit);
1722
1768
  });
1723
1769
  });
1724
1770
  })));
@@ -1729,24 +1775,24 @@ export const onResultIf = /*#__PURE__*/dual(3, (self, refinement, f) => uninterr
1729
1775
  * @experimental
1730
1776
  * @category resources & finalization
1731
1777
  */
1732
- export const ensuring = /*#__PURE__*/dual(2, (self, finalizer) => onResult(self, _ => finalizer));
1778
+ export const ensuring = /*#__PURE__*/dual(2, (self, finalizer) => onExit(self, _ => finalizer));
1733
1779
  /**
1734
1780
  * When the `Micro` effect fails, run the given finalizer effect with the
1735
- * `Failure` of the executed effect.
1781
+ * `MicroCause` of the executed effect.
1736
1782
  *
1737
- * @since 3.4.0
1783
+ * @since 3.4.6
1738
1784
  * @experimental
1739
1785
  * @category resources & finalization
1740
1786
  */
1741
- export const onFailure = /*#__PURE__*/dual(2, (self, f) => onResultIf(self, resultIsFailure, result => f(result.left)));
1787
+ export const onError = /*#__PURE__*/dual(2, (self, f) => onExitIf(self, exitIsFailure, exit => f(exit.left)));
1742
1788
  /**
1743
1789
  * If this `Micro` effect is aborted, run the finalizer effect.
1744
1790
  *
1745
- * @since 3.4.0
1791
+ * @since 3.4.6
1746
1792
  * @experimental
1747
1793
  * @category resources & finalization
1748
1794
  */
1749
- export const onAbort = /*#__PURE__*/dual(2, (self, finalizer) => onResultIf(self, resultIsAborted, _ => finalizer));
1795
+ export const onInterrupt = /*#__PURE__*/dual(2, (self, finalizer) => onExitIf(self, exitIsInterrupt, _ => finalizer));
1750
1796
  /**
1751
1797
  * Acquire a resource, use it, and then release the resource when the `use`
1752
1798
  * effect has completed.
@@ -1755,21 +1801,21 @@ export const onAbort = /*#__PURE__*/dual(2, (self, finalizer) => onResultIf(self
1755
1801
  * @experimental
1756
1802
  * @category resources & finalization
1757
1803
  */
1758
- export const acquireUseRelease = (acquire, use, release) => uninterruptibleMask(restore => flatMap(acquire, a => flatMap(asResult(restore(use(a))), result => andThen(release(a, result), fromResult(result)))));
1804
+ export const acquireUseRelease = (acquire, use, release) => uninterruptibleMask(restore => flatMap(acquire, a => flatMap(exit(restore(use(a))), exit => andThen(release(a, exit), fromExit(exit)))));
1759
1805
  // ----------------------------------------------------------------------------
1760
1806
  // interruption
1761
1807
  // ----------------------------------------------------------------------------
1762
1808
  /**
1763
1809
  * Abort the current `Micro` effect.
1764
1810
  *
1765
- * @since 3.4.0
1811
+ * @since 3.4.6
1766
1812
  * @experimental
1767
1813
  * @category interruption
1768
1814
  */
1769
- export const abort = /*#__PURE__*/make(function (env, onResult) {
1815
+ export const interrupt = /*#__PURE__*/make(function (env, onExit) {
1770
1816
  const controller = envGet(env, currentAbortController);
1771
1817
  controller.abort();
1772
- onResult(ResultAborted);
1818
+ onExit(exitInterrupt);
1773
1819
  });
1774
1820
  /**
1775
1821
  * Wrap the given `Micro` effect in an uninterruptible region, preventing the
@@ -1779,13 +1825,13 @@ export const abort = /*#__PURE__*/make(function (env, onResult) {
1779
1825
  * @experimental
1780
1826
  * @category interruption
1781
1827
  */
1782
- export const uninterruptible = self => unsafeMakeOptions(function (env, onResult) {
1828
+ export const uninterruptible = self => unsafeMakeOptions(function (env, onExit) {
1783
1829
  const nextEnv = envMutate(env, function (env) {
1784
1830
  env[currentInterruptible.key] = false;
1785
1831
  env[currentAbortSignal.key] = new AbortController().signal;
1786
1832
  return env;
1787
1833
  });
1788
- self[runSymbol](nextEnv, onResult);
1834
+ self[runSymbol](nextEnv, onExit);
1789
1835
  }, false);
1790
1836
  /**
1791
1837
  * Wrap the given `Micro` effect in an uninterruptible region, preventing the
@@ -1806,7 +1852,7 @@ export const uninterruptible = self => unsafeMakeOptions(function (env, onResult
1806
1852
  * )
1807
1853
  * )
1808
1854
  */
1809
- export const uninterruptibleMask = f => unsafeMakeOptions((env, onResult) => {
1855
+ export const uninterruptibleMask = f => unsafeMakeOptions((env, onExit) => {
1810
1856
  const isInterruptible = envGet(env, currentInterruptible);
1811
1857
  const effect = isInterruptible ? f(interruptible) : f(identity);
1812
1858
  const nextEnv = isInterruptible ? envMutate(env, function (env) {
@@ -1814,7 +1860,7 @@ export const uninterruptibleMask = f => unsafeMakeOptions((env, onResult) => {
1814
1860
  env[currentAbortSignal.key] = new AbortController().signal;
1815
1861
  return env;
1816
1862
  }) : env;
1817
- effect[runSymbol](nextEnv, onResult);
1863
+ effect[runSymbol](nextEnv, onExit);
1818
1864
  }, false);
1819
1865
  /**
1820
1866
  * Wrap the given `Micro` effect in an interruptible region, allowing the effect
@@ -1824,7 +1870,7 @@ export const uninterruptibleMask = f => unsafeMakeOptions((env, onResult) => {
1824
1870
  * @experimental
1825
1871
  * @category interruption
1826
1872
  */
1827
- export const interruptible = self => make((env, onResult) => {
1873
+ export const interruptible = self => make((env, onExit) => {
1828
1874
  const isInterruptible = envGet(env, currentInterruptible);
1829
1875
  let newEnv = env;
1830
1876
  if (!isInterruptible) {
@@ -1835,7 +1881,7 @@ export const interruptible = self => make((env, onResult) => {
1835
1881
  return env;
1836
1882
  });
1837
1883
  }
1838
- self[runSymbol](newEnv, onResult);
1884
+ self[runSymbol](newEnv, onExit);
1839
1885
  });
1840
1886
  /**
1841
1887
  * Runs all the provided effects in sequence respecting the structure provided in input.
@@ -1875,13 +1921,13 @@ export const all = (arg, options) => {
1875
1921
  * @experimental
1876
1922
  * @category collecting & elements
1877
1923
  */
1878
- export const forEach = (iterable, f, options) => make(function (env, onResult) {
1924
+ export const forEach = (iterable, f, options) => make(function (env, onExit) {
1879
1925
  const concurrencyOption = options?.concurrency === "inherit" ? envGet(env, currentConcurrency) : options?.concurrency ?? 1;
1880
1926
  const concurrency = concurrencyOption === "unbounded" ? Number.POSITIVE_INFINITY : Math.max(1, concurrencyOption);
1881
1927
  // abort
1882
1928
  const [envWithSignal, onAbort] = forkSignal(env);
1883
1929
  // iterate
1884
- let failure = undefined;
1930
+ let result = undefined;
1885
1931
  const items = Array.from(iterable);
1886
1932
  let length = items.length;
1887
1933
  const out = options?.discard ? undefined : new Array(length);
@@ -1897,26 +1943,26 @@ export const forEach = (iterable, f, options) => make(function (env, onResult) {
1897
1943
  index++;
1898
1944
  inProgress++;
1899
1945
  try {
1900
- f(item, currentIndex)[runSymbol](envWithSignal, function (result) {
1901
- if (result._tag === "Left") {
1902
- if (failure === undefined) {
1903
- failure = result;
1946
+ f(item, currentIndex)[runSymbol](envWithSignal, function (exit) {
1947
+ if (exit._tag === "Left") {
1948
+ if (result === undefined) {
1949
+ result = exit;
1904
1950
  length = index;
1905
1951
  onAbort();
1906
1952
  }
1907
1953
  } else if (out !== undefined) {
1908
- out[currentIndex] = result.right;
1954
+ out[currentIndex] = exit.right;
1909
1955
  }
1910
1956
  doneCount++;
1911
1957
  inProgress--;
1912
1958
  if (doneCount === length) {
1913
- onResult(failure ?? Either.right(out));
1959
+ onExit(result ?? Either.right(out));
1914
1960
  } else if (!pumping && inProgress < concurrency) {
1915
1961
  pump();
1916
1962
  }
1917
1963
  });
1918
1964
  } catch (err) {
1919
- failure = ResultFailUnexpected(err);
1965
+ result = exitDie(err);
1920
1966
  length = index;
1921
1967
  onAbort();
1922
1968
  }
@@ -1937,7 +1983,7 @@ export const forEach = (iterable, f, options) => make(function (env, onResult) {
1937
1983
  export const filter = (iterable, f, options) => filterMap(iterable, a => map(f(a), pass => {
1938
1984
  pass = options?.negate ? !pass : pass;
1939
1985
  return pass ? Option.some(a) : Option.none();
1940
- }));
1986
+ }), options);
1941
1987
  /**
1942
1988
  * Effectfully filter the elements of the provided iterable.
1943
1989
  *
@@ -2014,7 +2060,7 @@ class HandleImpl {
2014
2060
  parentSignal;
2015
2061
  [HandleTypeId];
2016
2062
  observers = new Set();
2017
- _result = undefined;
2063
+ _exit = undefined;
2018
2064
  _controller;
2019
2065
  isRoot;
2020
2066
  constructor(parentSignal, controller) {
@@ -2023,29 +2069,29 @@ class HandleImpl {
2023
2069
  this.isRoot = controller !== undefined;
2024
2070
  this._controller = controller ?? new AbortController();
2025
2071
  if (!this.isRoot) {
2026
- parentSignal.addEventListener("abort", this.unsafeAbort);
2072
+ parentSignal.addEventListener("abort", this.unsafeInterrupt);
2027
2073
  }
2028
2074
  }
2029
2075
  unsafePoll() {
2030
- return this._result ?? null;
2076
+ return this._exit ?? null;
2031
2077
  }
2032
- unsafeAbort = () => {
2078
+ unsafeInterrupt = () => {
2033
2079
  this._controller.abort();
2034
2080
  };
2035
- emit(result) {
2036
- if (this._result) {
2081
+ emit(exit) {
2082
+ if (this._exit) {
2037
2083
  return;
2038
2084
  }
2039
- this._result = result;
2085
+ this._exit = exit;
2040
2086
  if (!this.isRoot) {
2041
- this.parentSignal.removeEventListener("abort", this.unsafeAbort);
2087
+ this.parentSignal.removeEventListener("abort", this.unsafeInterrupt);
2042
2088
  }
2043
- this.observers.forEach(observer => observer(result));
2089
+ this.observers.forEach(observer => observer(exit));
2044
2090
  this.observers.clear();
2045
2091
  }
2046
2092
  addObserver(observer) {
2047
- if (this._result) {
2048
- return observer(this._result);
2093
+ if (this._exit) {
2094
+ return observer(this._exit);
2049
2095
  }
2050
2096
  this.observers.add(observer);
2051
2097
  }
@@ -2054,12 +2100,12 @@ class HandleImpl {
2054
2100
  }
2055
2101
  get await() {
2056
2102
  return suspend(() => {
2057
- if (this._result) {
2058
- return succeed(this._result);
2103
+ if (this._exit) {
2104
+ return succeed(this._exit);
2059
2105
  }
2060
2106
  return async(resume => {
2061
- function observer(result) {
2062
- resume(succeed(result));
2107
+ function observer(exit) {
2108
+ resume(succeed(exit));
2063
2109
  }
2064
2110
  this.addObserver(observer);
2065
2111
  return sync(() => {
@@ -2069,11 +2115,11 @@ class HandleImpl {
2069
2115
  });
2070
2116
  }
2071
2117
  get join() {
2072
- return flatMap(this.await, fromResult);
2118
+ return flatMap(this.await, fromExit);
2073
2119
  }
2074
- get abort() {
2120
+ get interrupt() {
2075
2121
  return suspend(() => {
2076
- this.unsafeAbort();
2122
+ this.unsafeInterrupt();
2077
2123
  return this.await;
2078
2124
  });
2079
2125
  }
@@ -2088,7 +2134,7 @@ class HandleImpl {
2088
2134
  * @experimental
2089
2135
  * @category handle & forking
2090
2136
  */
2091
- export const fork = self => make(function (env, onResult) {
2137
+ export const fork = self => make(function (env, onExit) {
2092
2138
  const signal = envGet(env, currentAbortSignal);
2093
2139
  const handle = new HandleImpl(signal);
2094
2140
  const nextEnv = envMutate(env, map => {
@@ -2097,11 +2143,11 @@ export const fork = self => make(function (env, onResult) {
2097
2143
  return map;
2098
2144
  });
2099
2145
  yieldAdd(() => {
2100
- self[runSymbol](nextEnv, result => {
2101
- handle.emit(result);
2146
+ self[runSymbol](nextEnv, exit => {
2147
+ handle.emit(exit);
2102
2148
  });
2103
2149
  });
2104
- onResult(Either.right(handle));
2150
+ onExit(Either.right(handle));
2105
2151
  });
2106
2152
  /**
2107
2153
  * Run the `Micro` effect in a new `Handle` that can be awaited, joined, or
@@ -2113,7 +2159,7 @@ export const fork = self => make(function (env, onResult) {
2113
2159
  * @experimental
2114
2160
  * @category handle & forking
2115
2161
  */
2116
- export const forkDaemon = self => make(function (env, onResult) {
2162
+ export const forkDaemon = self => make(function (env, onExit) {
2117
2163
  const controller = new AbortController();
2118
2164
  const handle = new HandleImpl(controller.signal, controller);
2119
2165
  const nextEnv = envMutate(env, map => {
@@ -2122,11 +2168,11 @@ export const forkDaemon = self => make(function (env, onResult) {
2122
2168
  return map;
2123
2169
  });
2124
2170
  yieldAdd(() => {
2125
- self[runSymbol](nextEnv, result => {
2126
- handle.emit(result);
2171
+ self[runSymbol](nextEnv, exit => {
2172
+ handle.emit(exit);
2127
2173
  });
2128
2174
  });
2129
- onResult(Either.right(handle));
2175
+ onExit(Either.right(handle));
2130
2176
  });
2131
2177
  /**
2132
2178
  * Run the `Micro` effect in a new `Handle` that can be awaited, joined, or
@@ -2138,7 +2184,7 @@ export const forkDaemon = self => make(function (env, onResult) {
2138
2184
  * @experimental
2139
2185
  * @category handle & forking
2140
2186
  */
2141
- export const forkIn = /*#__PURE__*/dual(2, (self, scope) => uninterruptibleMask(restore => flatMap(scope.fork, scope => tap(restore(forkDaemon(onResult(self, result => scope.close(result)))), fiber => scope.addFinalizer(_ => asVoid(fiber.abort))))));
2187
+ export const forkIn = /*#__PURE__*/dual(2, (self, scope) => uninterruptibleMask(restore => flatMap(scope.fork, scope => tap(restore(forkDaemon(onExit(self, exit => scope.close(exit)))), fiber => scope.addFinalizer(_ => asVoid(fiber.interrupt))))));
2142
2188
  /**
2143
2189
  * Run the `Micro` effect in a new `Handle` that can be awaited, joined, or
2144
2190
  * aborted.
@@ -2171,8 +2217,8 @@ export const forkScoped = self => flatMap(scope, scope => forkIn(self, scope));
2171
2217
  * Micro.runFork
2172
2218
  * )
2173
2219
  *
2174
- * handle.addObserver((result) => {
2175
- * console.log(result)
2220
+ * handle.addObserver((exit) => {
2221
+ * console.log(exit)
2176
2222
  * })
2177
2223
  */
2178
2224
  export const runFork = (effect, options) => {
@@ -2182,17 +2228,17 @@ export const runFork = (effect, options) => {
2182
2228
  refs[currentAbortSignal.key] = controller.signal;
2183
2229
  const env = envMake(refs);
2184
2230
  const handle = new HandleImpl(controller.signal, controller);
2185
- effect[runSymbol](envSet(env, currentAbortSignal, handle._controller.signal), result => {
2186
- handle.emit(result);
2231
+ effect[runSymbol](envSet(env, currentAbortSignal, handle._controller.signal), exit => {
2232
+ handle.emit(exit);
2187
2233
  if (options?.signal) {
2188
- options.signal.removeEventListener("abort", handle.unsafeAbort);
2234
+ options.signal.removeEventListener("abort", handle.unsafeInterrupt);
2189
2235
  }
2190
2236
  });
2191
2237
  if (options?.signal) {
2192
2238
  if (options.signal.aborted) {
2193
- handle.unsafeAbort();
2239
+ handle.unsafeInterrupt();
2194
2240
  } else {
2195
- options.signal.addEventListener("abort", handle.unsafeAbort, {
2241
+ options.signal.addEventListener("abort", handle.unsafeInterrupt, {
2196
2242
  once: true
2197
2243
  });
2198
2244
  }
@@ -2201,13 +2247,13 @@ export const runFork = (effect, options) => {
2201
2247
  };
2202
2248
  /**
2203
2249
  * Execute the `Micro` effect and return a `Promise` that resolves with the
2204
- * `Result` of the computation.
2250
+ * `MicroExit` of the computation.
2205
2251
  *
2206
- * @since 3.4.0
2252
+ * @since 3.4.6
2207
2253
  * @experimental
2208
2254
  * @category execution
2209
2255
  */
2210
- export const runPromiseResult = (effect, options) => new Promise((resolve, _reject) => {
2256
+ export const runPromiseExit = (effect, options) => new Promise((resolve, _reject) => {
2211
2257
  const handle = runFork(effect, options);
2212
2258
  handle.addObserver(resolve);
2213
2259
  });
@@ -2219,32 +2265,32 @@ export const runPromiseResult = (effect, options) => new Promise((resolve, _reje
2219
2265
  * @experimental
2220
2266
  * @category execution
2221
2267
  */
2222
- export const runPromise = (effect, options) => runPromiseResult(effect, options).then(result => {
2223
- if (result._tag === "Left") {
2224
- throw result.left;
2268
+ export const runPromise = (effect, options) => runPromiseExit(effect, options).then(exit => {
2269
+ if (exit._tag === "Left") {
2270
+ throw exit.left;
2225
2271
  }
2226
- return result.right;
2272
+ return exit.right;
2227
2273
  });
2228
2274
  /**
2229
- * Attempt to execute the `Micro` effect synchronously and return the `Result`.
2275
+ * Attempt to execute the `Micro` effect synchronously and return the `MicroExit`.
2230
2276
  *
2231
2277
  * If any asynchronous effects are encountered, the function will return a
2232
- * FailureUnexpected containing the `Handle`.
2278
+ * `CauseDie` containing the `Handle`.
2233
2279
  *
2234
- * @since 3.4.0
2280
+ * @since 3.4.6
2235
2281
  * @experimental
2236
2282
  * @category execution
2237
2283
  */
2238
- export const runSyncResult = effect => {
2284
+ export const runSyncExit = effect => {
2239
2285
  const handle = runFork(effect);
2240
2286
  while (yieldState.tasks.length > 0) {
2241
2287
  yieldRunTasks();
2242
2288
  }
2243
- const result = handle.unsafePoll();
2244
- if (result === null) {
2245
- return ResultFailUnexpected(handle);
2289
+ const exit = handle.unsafePoll();
2290
+ if (exit === null) {
2291
+ return exitDie(handle);
2246
2292
  }
2247
- return result;
2293
+ return exit;
2248
2294
  };
2249
2295
  /**
2250
2296
  * Attempt to execute the `Micro` effect synchronously and return the success
@@ -2255,16 +2301,16 @@ export const runSyncResult = effect => {
2255
2301
  * @category execution
2256
2302
  */
2257
2303
  export const runSync = effect => {
2258
- const result = runSyncResult(effect);
2259
- if (result._tag === "Left") {
2260
- throw result.left;
2304
+ const exit = runSyncExit(effect);
2305
+ if (exit._tag === "Left") {
2306
+ throw exit.left;
2261
2307
  }
2262
- return result.right;
2308
+ return exit.right;
2263
2309
  };
2264
2310
  const YieldableError = /*#__PURE__*/function () {
2265
2311
  class YieldableError extends globalThis.Error {
2266
- [runSymbol](_env, onResult) {
2267
- onResult(ResultFail(this));
2312
+ [runSymbol](_env, onExit) {
2313
+ onExit(exitFail(this));
2268
2314
  }
2269
2315
  toString() {
2270
2316
  return this.message ? `${this.name}: ${this.message}` : this.name;
@@ -2322,4 +2368,12 @@ export const TaggedError = tag => {
2322
2368
  * @category errors
2323
2369
  */
2324
2370
  export class NoSuchElementException extends TaggedError("NoSuchElementException") {}
2371
+ /**
2372
+ * Represents a checked exception which occurs when a timeout occurs.
2373
+ *
2374
+ * @since 3.4.4
2375
+ * @experimental
2376
+ * @category errors
2377
+ */
2378
+ export class TimeoutException extends TaggedError("TimeoutException") {}
2325
2379
  //# sourceMappingURL=Micro.js.map