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/cjs/Micro.js CHANGED
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.matchFailure = exports.match = exports.mapFailure = exports.mapError = exports.map = exports.make = exports.locally = exports.let = exports.isMicro = exports.isHandle = exports.interruptible = exports.ignoreLogged = exports.ignore = exports.getEnvRef = exports.gen = exports.fromResultSync = exports.fromResult = exports.fromOption = exports.fromEither = exports.forkScoped = exports.forkIn = exports.forkDaemon = exports.fork = exports.forever = exports.forEach = exports.flip = exports.flatten = exports.flatMap = exports.filterOrFailWith = exports.filterOrFail = exports.filterMap = exports.filter = exports.failureWithTrace = exports.failureSquash = exports.failureIsUnexpected = exports.failureIsExpected = exports.failureIsAborted = exports.failWithSync = exports.failWith = exports.failSync = exports.fail = exports.envUnsafeMakeEmpty = exports.envSet = exports.envRefMake = exports.envMutate = exports.envMake = exports.envGet = exports.ensuring = exports.either = exports.die = exports.delayWithRecurs = exports.delayWithMaxElapsed = exports.delayWithMax = exports.delaySpaced = exports.delayExponential = exports.delay = exports.currentMaxDepthBeforeYield = exports.currentContext = exports.currentConcurrency = exports.currentAbortSignal = exports.currentAbortController = exports.context = exports.catchUnexpected = exports.catchTag = exports.catchIf = exports.catchFailureIf = exports.catchFailure = exports.catchExpected = exports.bindTo = exports.bind = exports.async = exports.asVoid = exports.asSome = exports.asResult = exports.as = exports.andThen = exports.all = exports.addFinalizer = exports.acquireUseRelease = exports.acquireRelease = exports.abort = exports.TypeId = exports.TaggedError = exports.ResultSuccess = exports.ResultFailWith = exports.ResultFailUnexpected = exports.ResultFail = exports.ResultAborted = exports.NoSuchElementException = exports.MicroScopeTypeId = exports.MicroScope = exports.HandleTypeId = exports.FailureUnexpected = exports.FailureTypeId = exports.FailureExpected = exports.FailureAborted = exports.Error = exports.EnvTypeId = exports.EnvRefTypeId = exports.Do = void 0;
7
- exports.zipWith = exports.zip = exports.yieldNow = exports.yieldFlush = exports.withTrace = exports.withConcurrency = exports.when = exports.void = exports.uninterruptibleMask = exports.uninterruptible = exports.tryPromise = exports.try = exports.timeoutOrElse = exports.timeout = exports.tapUnexpected = exports.tapFailureIf = exports.tapFailure = exports.tapExpected = exports.tap = exports.sync = exports.suspend = exports.succeedSome = exports.succeedNone = exports.succeed = exports.sleep = exports.serviceOption = exports.service = exports.scoped = exports.scopeUnsafeMake = exports.scopeMake = exports.scope = exports.sandbox = exports.runSyncResult = exports.runSync = exports.runSymbol = exports.runPromiseResult = exports.runPromise = exports.runFork = exports.retry = exports.resultVoid = exports.resultIsSuccess = exports.resultIsFailureUnexpected = exports.resultIsFailureExpected = exports.resultIsFailure = exports.resultIsAborted = exports.repeatResult = exports.repeat = exports.raceFirst = exports.raceAllFirst = exports.raceAll = exports.race = exports.provideServiceMicro = exports.provideService = exports.provideScope = exports.provideContext = exports.promise = exports.orElseSucceed = exports.orDie = exports.option = exports.onResultIf = exports.onResult = exports.onFailure = exports.onAbort = exports.never = exports.matchMicro = exports.matchFailureMicro = void 0;
6
+ exports.mapErrorCause = exports.mapError = exports.map = exports.make = exports.locally = exports.let = exports.isMicro = exports.isHandle = exports.interruptible = exports.interrupt = exports.ignoreLogged = exports.ignore = exports.getEnvRef = exports.gen = exports.fromOption = exports.fromExitSync = exports.fromExit = exports.fromEither = exports.forkScoped = exports.forkIn = exports.forkDaemon = exports.fork = exports.forever = exports.forEach = exports.flip = exports.flatten = exports.flatMap = exports.filterOrFailCause = exports.filterOrFail = exports.filterMap = exports.filter = exports.failSync = exports.failCauseSync = exports.failCause = exports.fail = exports.exitVoid = exports.exitSucceed = exports.exitIsSuccess = exports.exitIsInterrupt = exports.exitIsFailure = exports.exitIsFail = exports.exitIsDie = exports.exitInterrupt = exports.exitFailCause = exports.exitFail = exports.exitDie = exports.exit = exports.envUnsafeMakeEmpty = exports.envSet = exports.envRefMake = exports.envMutate = exports.envMake = exports.envGet = exports.ensuring = exports.either = exports.die = exports.delay = exports.currentMaxDepthBeforeYield = exports.currentContext = exports.currentConcurrency = exports.currentAbortSignal = exports.currentAbortController = exports.context = exports.causeWithTrace = exports.causeSquash = exports.causeIsInterrupt = exports.causeIsFail = exports.causeIsDie = exports.causeInterrupt = exports.causeFail = exports.causeDie = exports.catchTag = exports.catchIf = exports.catchCauseIf = exports.catchAllDefect = exports.catchAllCause = exports.catchAll = exports.bindTo = exports.bind = exports.async = exports.asVoid = exports.asSome = exports.as = exports.andThen = exports.all = exports.addFinalizer = exports.acquireUseRelease = exports.acquireRelease = exports.TypeId = exports.TimeoutException = exports.TaggedError = exports.NoSuchElementException = exports.MicroScopeTypeId = exports.MicroScope = exports.MicroCauseTypeId = exports.HandleTypeId = exports.Error = exports.EnvTypeId = exports.EnvRefTypeId = exports.Do = void 0;
7
+ exports.zipWith = exports.zip = exports.yieldNow = exports.yieldFlush = exports.withTrace = exports.withConcurrency = exports.when = exports.void = exports.uninterruptibleMask = exports.uninterruptible = exports.tryPromise = exports.try = exports.timeoutOrElse = exports.timeoutOption = exports.timeout = exports.tapErrorCauseIf = exports.tapErrorCause = exports.tapError = exports.tapDefect = exports.tap = exports.sync = exports.suspend = exports.succeedSome = exports.succeedNone = exports.succeed = exports.sleep = exports.serviceOption = exports.service = exports.scoped = exports.scopeUnsafeMake = exports.scopeMake = exports.scope = exports.scheduleWithMaxElapsed = exports.scheduleWithMaxDelay = exports.scheduleUnion = exports.scheduleSpaced = exports.scheduleRecurs = exports.scheduleIntersect = exports.scheduleExponential = exports.scheduleAddDelay = exports.sandbox = exports.runSyncExit = exports.runSync = exports.runSymbol = exports.runPromiseExit = exports.runPromise = exports.runFork = exports.retry = exports.repeatExit = exports.repeat = exports.raceFirst = exports.raceAllFirst = exports.raceAll = exports.race = exports.provideServiceEffect = exports.provideService = exports.provideScope = exports.provideContext = exports.promise = exports.orElseSucceed = exports.orDie = exports.option = exports.onInterrupt = exports.onExitIf = exports.onExit = exports.onError = exports.never = exports.matchEffect = exports.matchCauseEffect = exports.matchCause = exports.match = void 0;
8
8
  var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Context.js"));
9
9
  var Effectable = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Effectable.js"));
10
10
  var Either = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Either.js"));
@@ -62,34 +62,34 @@ const runSymbol = exports.runSymbol = /*#__PURE__*/Symbol.for("effect/Micro/runS
62
62
  */
63
63
  const isMicro = u => typeof u === "object" && u !== null && TypeId in u;
64
64
  // ----------------------------------------------------------------------------
65
- // Failures
65
+ // MicroCause
66
66
  // ----------------------------------------------------------------------------
67
67
  /**
68
- * @since 3.4.0
68
+ * @since 3.4.6
69
69
  * @experimental
70
- * @category failure
70
+ * @category MicroCause
71
71
  */
72
72
  exports.isMicro = isMicro;
73
- const FailureTypeId = exports.FailureTypeId = /*#__PURE__*/Symbol.for("effect/Micro/Failure");
74
- const failureVariance = {
73
+ const MicroCauseTypeId = exports.MicroCauseTypeId = /*#__PURE__*/Symbol.for("effect/Micro/MicroCause");
74
+ const microCauseVariance = {
75
75
  _E: _Function.identity
76
76
  };
77
- class FailureImpl extends globalThis.Error {
77
+ class MicroCauseImpl extends globalThis.Error {
78
78
  _tag;
79
79
  traces;
80
- [FailureTypeId];
80
+ [MicroCauseTypeId];
81
81
  constructor(_tag, originalError, traces) {
82
- const failureName = `Failure${_tag}`;
82
+ const causeName = `MicroCause.${_tag}`;
83
83
  let name;
84
84
  let message;
85
85
  let stack;
86
86
  if (originalError instanceof globalThis.Error) {
87
- name = `(${failureName}) ${originalError.name}`;
87
+ name = `(${causeName}) ${originalError.name}`;
88
88
  message = originalError.message;
89
89
  const messageLines = message.split("\n").length;
90
- stack = originalError.stack ? `(${failureName}) ${originalError.stack.split("\n").slice(0, messageLines + 3).join("\n")}` : `${name}: ${message}`;
90
+ stack = originalError.stack ? `(${causeName}) ${originalError.stack.split("\n").slice(0, messageLines + 3).join("\n")}` : `${name}: ${message}`;
91
91
  } else {
92
- name = failureName;
92
+ name = causeName;
93
93
  message = (0, _Inspectable.toStringUnknown)(originalError, 0);
94
94
  stack = `${name}: ${message}`;
95
95
  }
@@ -99,7 +99,7 @@ class FailureImpl extends globalThis.Error {
99
99
  super(message);
100
100
  this._tag = _tag;
101
101
  this.traces = traces;
102
- this[FailureTypeId] = failureVariance;
102
+ this[MicroCauseTypeId] = microCauseVariance;
103
103
  this.name = name;
104
104
  this.stack = stack;
105
105
  }
@@ -113,158 +113,161 @@ class FailureImpl extends globalThis.Error {
113
113
  return this.stack;
114
114
  }
115
115
  }
116
- class FailureExpectedImpl extends FailureImpl {
116
+ class FailImpl extends MicroCauseImpl {
117
117
  error;
118
118
  constructor(error, traces = []) {
119
- super("Expected", error, traces);
119
+ super("Fail", error, traces);
120
120
  this.error = error;
121
121
  }
122
122
  }
123
123
  /**
124
- * @since 3.4.0
124
+ * @since 3.4.6
125
125
  * @experimental
126
- * @category failure
126
+ * @category MicroCause
127
127
  */
128
- const FailureExpected = (error, traces = []) => new FailureExpectedImpl(error, traces);
129
- exports.FailureExpected = FailureExpected;
130
- class FailureUnexpectedImpl extends FailureImpl {
128
+ const causeFail = (error, traces = []) => new FailImpl(error, traces);
129
+ exports.causeFail = causeFail;
130
+ class DieImpl extends MicroCauseImpl {
131
131
  defect;
132
132
  constructor(defect, traces = []) {
133
- super("Unexpected", defect, traces);
133
+ super("Die", defect, traces);
134
134
  this.defect = defect;
135
135
  }
136
136
  }
137
137
  /**
138
- * @since 3.4.0
138
+ * @since 3.4.6
139
139
  * @experimental
140
- * @category failure
140
+ * @category MicroCause
141
141
  */
142
- const FailureUnexpected = (defect, traces = []) => new FailureUnexpectedImpl(defect, traces);
143
- exports.FailureUnexpected = FailureUnexpected;
144
- class FailureAbortedImpl extends FailureImpl {
142
+ const causeDie = (defect, traces = []) => new DieImpl(defect, traces);
143
+ exports.causeDie = causeDie;
144
+ class InterruptImpl extends MicroCauseImpl {
145
145
  constructor(traces = []) {
146
- super("Aborted", "aborted", traces);
146
+ super("Interrupt", "interrupted", traces);
147
147
  }
148
148
  }
149
149
  /**
150
- * @since 3.4.0
150
+ * @since 3.4.6
151
151
  * @experimental
152
- * @category failure
152
+ * @category MicroCause
153
153
  */
154
- const FailureAborted = (traces = []) => new FailureAbortedImpl(traces);
154
+ const causeInterrupt = (traces = []) => new InterruptImpl(traces);
155
155
  /**
156
- * @since 3.4.0
156
+ * @since 3.4.6
157
157
  * @experimental
158
- * @category failure
158
+ * @category MicroCause
159
159
  */
160
- exports.FailureAborted = FailureAborted;
161
- const failureIsExpected = self => self._tag === "Expected";
160
+ exports.causeInterrupt = causeInterrupt;
161
+ const causeIsFail = self => self._tag === "Fail";
162
162
  /**
163
- * @since 3.4.0
163
+ * @since 3.4.6
164
164
  * @experimental
165
- * @category failure
165
+ * @category MicroCause
166
166
  */
167
- exports.failureIsExpected = failureIsExpected;
168
- const failureIsUnexpected = self => self._tag === "Unexpected";
167
+ exports.causeIsFail = causeIsFail;
168
+ const causeIsDie = self => self._tag === "Die";
169
169
  /**
170
- * @since 3.4.0
170
+ * @since 3.4.6
171
171
  * @experimental
172
- * @category failure
172
+ * @category MicroCause
173
173
  */
174
- exports.failureIsUnexpected = failureIsUnexpected;
175
- const failureIsAborted = self => self._tag === "Aborted";
174
+ exports.causeIsDie = causeIsDie;
175
+ const causeIsInterrupt = self => self._tag === "Interrupt";
176
176
  /**
177
- * @since 3.4.0
177
+ * @since 3.4.6
178
178
  * @experimental
179
- * @category failure
179
+ * @category MicroCause
180
180
  */
181
- exports.failureIsAborted = failureIsAborted;
182
- const failureSquash = self => self._tag === "Expected" ? self.error : self._tag === "Unexpected" ? self.defect : self;
181
+ exports.causeIsInterrupt = causeIsInterrupt;
182
+ const causeSquash = self => self._tag === "Fail" ? self.error : self._tag === "Die" ? self.defect : self;
183
183
  /**
184
- * @since 3.4.0
184
+ * @since 3.4.6
185
185
  * @experimental
186
- * @category failure
186
+ * @category MicroCause
187
187
  */
188
- exports.failureSquash = failureSquash;
189
- const failureWithTrace = exports.failureWithTrace = /*#__PURE__*/(0, _Function.dual)(2, (self, trace) => {
190
- if (self._tag === "Expected") {
191
- return FailureExpected(self.error, [...self.traces, trace]);
192
- } else if (self._tag === "Unexpected") {
193
- return FailureUnexpected(self.defect, [...self.traces, trace]);
188
+ exports.causeSquash = causeSquash;
189
+ const causeWithTrace = exports.causeWithTrace = /*#__PURE__*/(0, _Function.dual)(2, (self, trace) => {
190
+ const traces = [...self.traces, trace];
191
+ switch (self._tag) {
192
+ case "Die":
193
+ return causeDie(self.defect, traces);
194
+ case "Interrupt":
195
+ return causeInterrupt(traces);
196
+ case "Fail":
197
+ return causeFail(self.error, traces);
194
198
  }
195
- return FailureAborted([...self.traces, trace]);
196
199
  });
197
200
  /**
198
- * @since 3.4.0
201
+ * @since 3.4.6
199
202
  * @experimental
200
- * @category result
203
+ * @category MicroExit
201
204
  */
202
- const ResultAborted = exports.ResultAborted = /*#__PURE__*/Either.left( /*#__PURE__*/FailureAborted());
205
+ const exitInterrupt = exports.exitInterrupt = /*#__PURE__*/Either.left( /*#__PURE__*/causeInterrupt());
203
206
  /**
204
- * @since 3.4.0
207
+ * @since 3.4.6
205
208
  * @experimental
206
- * @category result
209
+ * @category MicroExit
207
210
  */
208
- const ResultSuccess = exports.ResultSuccess = Either.right;
211
+ const exitSucceed = exports.exitSucceed = Either.right;
209
212
  /**
210
- * @since 3.4.0
213
+ * @since 3.4.6
211
214
  * @experimental
212
- * @category result
215
+ * @category MicroExit
213
216
  */
214
- const ResultFail = e => Either.left(FailureExpected(e));
217
+ const exitFail = e => Either.left(causeFail(e));
215
218
  /**
216
- * @since 3.4.0
219
+ * @since 3.4.6
217
220
  * @experimental
218
- * @category result
221
+ * @category MicroExit
219
222
  */
220
- exports.ResultFail = ResultFail;
221
- const ResultFailUnexpected = defect => Either.left(FailureUnexpected(defect));
223
+ exports.exitFail = exitFail;
224
+ const exitDie = defect => Either.left(causeDie(defect));
222
225
  /**
223
- * @since 3.4.0
226
+ * @since 3.4.6
224
227
  * @experimental
225
- * @category result
228
+ * @category MicroExit
226
229
  */
227
- exports.ResultFailUnexpected = ResultFailUnexpected;
228
- const ResultFailWith = exports.ResultFailWith = Either.left;
230
+ exports.exitDie = exitDie;
231
+ const exitFailCause = exports.exitFailCause = Either.left;
229
232
  /**
230
- * @since 3.4.0
233
+ * @since 3.4.6
231
234
  * @experimental
232
- * @category result
235
+ * @category MicroExit
233
236
  */
234
- const resultIsSuccess = exports.resultIsSuccess = Either.isRight;
237
+ const exitIsSuccess = exports.exitIsSuccess = Either.isRight;
235
238
  /**
236
- * @since 3.4.0
239
+ * @since 3.4.6
237
240
  * @experimental
238
- * @category result
241
+ * @category MicroExit
239
242
  */
240
- const resultIsFailure = exports.resultIsFailure = Either.isLeft;
243
+ const exitIsFailure = exports.exitIsFailure = Either.isLeft;
241
244
  /**
242
- * @since 3.4.0
245
+ * @since 3.4.6
243
246
  * @experimental
244
- * @category result
247
+ * @category MicroExit
245
248
  */
246
- const resultIsAborted = self => resultIsFailure(self) && self.left._tag === "Aborted";
249
+ const exitIsInterrupt = self => exitIsFailure(self) && self.left._tag === "Interrupt";
247
250
  /**
248
- * @since 3.4.0
251
+ * @since 3.4.6
249
252
  * @experimental
250
- * @category result
253
+ * @category MicroExit
251
254
  */
252
- exports.resultIsAborted = resultIsAborted;
253
- const resultIsFailureExpected = self => resultIsFailure(self) && self.left._tag === "Expected";
255
+ exports.exitIsInterrupt = exitIsInterrupt;
256
+ const exitIsFail = self => exitIsFailure(self) && self.left._tag === "Fail";
254
257
  /**
255
- * @since 3.4.0
258
+ * @since 3.4.6
256
259
  * @experimental
257
- * @category result
260
+ * @category MicroExit
258
261
  */
259
- exports.resultIsFailureExpected = resultIsFailureExpected;
260
- const resultIsFailureUnexpected = self => resultIsFailure(self) && self.left._tag === "Unexpected";
262
+ exports.exitIsFail = exitIsFail;
263
+ const exitIsDie = self => exitIsFailure(self) && self.left._tag === "Die";
261
264
  /**
262
- * @since 3.4.0
265
+ * @since 3.4.6
263
266
  * @experimental
264
- * @category result
267
+ * @category MicroExit
265
268
  */
266
- exports.resultIsFailureUnexpected = resultIsFailureUnexpected;
267
- const resultVoid = exports.resultVoid = /*#__PURE__*/ResultSuccess(void 0);
269
+ exports.exitIsDie = exitIsDie;
270
+ const exitVoid = exports.exitVoid = /*#__PURE__*/exitSucceed(void 0);
268
271
  // ----------------------------------------------------------------------------
269
272
  // env
270
273
  // ----------------------------------------------------------------------------
@@ -341,8 +344,8 @@ const envMutate = exports.envMutate = /*#__PURE__*/(0, _Function.dual)(2, (self,
341
344
  * @experimental
342
345
  * @category environment
343
346
  */
344
- const service = tag => make(function (env, onResult) {
345
- onResult(ResultSuccess(Context.get(envGet(env, currentContext), tag)));
347
+ const service = tag => make(function (env, onExit) {
348
+ onExit(exitSucceed(Context.get(envGet(env, currentContext), tag)));
346
349
  });
347
350
  /**
348
351
  * Access the given `Context.Tag` from the environment, without tracking the
@@ -356,8 +359,8 @@ const service = tag => make(function (env, onResult) {
356
359
  * @category environment
357
360
  */
358
361
  exports.service = service;
359
- const serviceOption = tag => make(function (env, onResult) {
360
- onResult(ResultSuccess(Context.getOption(envGet(env, currentContext), tag)));
362
+ const serviceOption = tag => make(function (env, onExit) {
363
+ onExit(exitSucceed(Context.getOption(envGet(env, currentContext), tag)));
361
364
  });
362
365
  /**
363
366
  * Retrieve the current value of the given `EnvRef`.
@@ -367,7 +370,7 @@ const serviceOption = tag => make(function (env, onResult) {
367
370
  * @category environment
368
371
  */
369
372
  exports.serviceOption = serviceOption;
370
- const getEnvRef = envRef => make((env, onResult) => onResult(Either.right(envGet(env, envRef))));
373
+ const getEnvRef = envRef => make((env, onExit) => onExit(Either.right(envGet(env, envRef))));
371
374
  /**
372
375
  * Set the value of the given `EnvRef` for the duration of the effect.
373
376
  *
@@ -376,7 +379,7 @@ const getEnvRef = envRef => make((env, onResult) => onResult(Either.right(envGet
376
379
  * @category environment
377
380
  */
378
381
  exports.getEnvRef = getEnvRef;
379
- const locally = exports.locally = /*#__PURE__*/(0, _Function.dual)(3, (self, fiberRef, value) => make((env, onResult) => self[runSymbol](envSet(env, fiberRef, value), onResult)));
382
+ const locally = exports.locally = /*#__PURE__*/(0, _Function.dual)(3, (self, fiberRef, value) => make((env, onExit) => self[runSymbol](envSet(env, fiberRef, value), onExit)));
380
383
  /**
381
384
  * Access the current `Context` from the environment.
382
385
  *
@@ -393,10 +396,10 @@ const context = () => getEnvRef(currentContext);
393
396
  * @category environment
394
397
  */
395
398
  exports.context = context;
396
- const provideContext = exports.provideContext = /*#__PURE__*/(0, _Function.dual)(2, (self, provided) => make(function (env, onResult) {
399
+ const provideContext = exports.provideContext = /*#__PURE__*/(0, _Function.dual)(2, (self, provided) => make(function (env, onExit) {
397
400
  const context = envGet(env, currentContext);
398
401
  const nextEnv = envSet(env, currentContext, Context.merge(context, provided));
399
- self[runSymbol](nextEnv, onResult);
402
+ self[runSymbol](nextEnv, onExit);
400
403
  }));
401
404
  /**
402
405
  * Add the provided service to the current context.
@@ -405,20 +408,20 @@ const provideContext = exports.provideContext = /*#__PURE__*/(0, _Function.dual)
405
408
  * @experimental
406
409
  * @category environment
407
410
  */
408
- const provideService = exports.provideService = /*#__PURE__*/(0, _Function.dual)(3, (self, tag, service) => make(function (env, onResult) {
411
+ const provideService = exports.provideService = /*#__PURE__*/(0, _Function.dual)(3, (self, tag, service) => make(function (env, onExit) {
409
412
  const context = envGet(env, currentContext);
410
413
  const nextEnv = envSet(env, currentContext, Context.add(context, tag, service));
411
- self[runSymbol](nextEnv, onResult);
414
+ self[runSymbol](nextEnv, onExit);
412
415
  }));
413
416
  /**
414
417
  * Create a service using the provided `Micro` effect, and add it to the
415
418
  * current context.
416
419
  *
417
- * @since 3.4.0
420
+ * @since 3.4.6
418
421
  * @experimental
419
422
  * @category environment
420
423
  */
421
- const provideServiceMicro = exports.provideServiceMicro = /*#__PURE__*/(0, _Function.dual)(3, (self, tag, acquire) => flatMap(acquire, service => provideService(self, tag, service)));
424
+ const provideServiceEffect = exports.provideServiceEffect = /*#__PURE__*/(0, _Function.dual)(3, (self, tag, acquire) => flatMap(acquire, service => provideService(self, tag, service)));
422
425
  // ========================================================================
423
426
  // Env refs
424
427
  // ========================================================================
@@ -509,21 +512,21 @@ const unsafeMake = run => {
509
512
  self[runSymbol] = run;
510
513
  return self;
511
514
  };
512
- const unsafeMakeOptions = (run, checkAbort) => unsafeMake(function execute(env, onResult) {
515
+ const unsafeMakeOptions = (run, checkAbort) => unsafeMake(function execute(env, onExit) {
513
516
  if (checkAbort && env.refs[currentInterruptible.key] !== false && env.refs[currentAbortSignal.key].aborted) {
514
- return onResult(ResultAborted);
517
+ return onExit(exitInterrupt);
515
518
  }
516
519
  microDepthState.depth++;
517
520
  if (microDepthState.depth === 1) {
518
521
  microDepthState.maxDepthBeforeYield = envGet(env, currentMaxDepthBeforeYield);
519
522
  }
520
523
  if (microDepthState.depth >= microDepthState.maxDepthBeforeYield) {
521
- yieldAdd(() => execute(env, onResult));
524
+ yieldAdd(() => execute(env, onExit));
522
525
  } else {
523
526
  try {
524
- run(env, onResult);
527
+ run(env, onExit);
525
528
  } catch (err) {
526
- onResult(ResultFailUnexpected(err));
529
+ onExit(exitDie(err));
527
530
  }
528
531
  }
529
532
  microDepthState.depth--;
@@ -539,26 +542,26 @@ const unsafeMakeOptions = (run, checkAbort) => unsafeMake(function execute(env,
539
542
  */
540
543
  const make = run => unsafeMakeOptions(run, true);
541
544
  /**
542
- * Converts a `Result` into a `Micro` effect.
545
+ * Converts a `MicroExit` into a `Micro` effect.
543
546
  *
544
- * @since 3.4.0
547
+ * @since 3.4.6
545
548
  * @experimental
546
549
  * @category constructors
547
550
  */
548
551
  exports.make = make;
549
- const fromResult = self => make(function (_env, onResult) {
550
- onResult(self);
552
+ const fromExit = self => make(function (_env, onExit) {
553
+ onExit(self);
551
554
  });
552
555
  /**
553
- * Converts a lazy `Result` into a `Micro` effect.
556
+ * Converts a lazy `MicroExit` into a `Micro` effect.
554
557
  *
555
- * @since 3.4.0
558
+ * @since 3.4.6
556
559
  * @experimental
557
560
  * @category constructors
558
561
  */
559
- exports.fromResult = fromResult;
560
- const fromResultSync = self => make(function (_env, onResult) {
561
- onResult(self());
562
+ exports.fromExit = fromExit;
563
+ const fromExitSync = self => make(function (_env, onExit) {
564
+ onExit(self());
562
565
  });
563
566
  /**
564
567
  * Creates a `Micro` effect that will succeed with the specified constant value.
@@ -567,8 +570,8 @@ const fromResultSync = self => make(function (_env, onResult) {
567
570
  * @experimental
568
571
  * @category constructors
569
572
  */
570
- exports.fromResultSync = fromResultSync;
571
- const succeed = a => fromResult(ResultSuccess(a));
573
+ exports.fromExitSync = fromExitSync;
574
+ const succeed = a => fromExit(exitSucceed(a));
572
575
  /**
573
576
  * Creates a `Micro` effect that will succeed with `Option.Some` of the value.
574
577
  *
@@ -590,18 +593,18 @@ const succeedNone = exports.succeedNone = /*#__PURE__*/succeed( /*#__PURE__*/Opt
590
593
  /**
591
594
  * Creates a `Micro` effect that will fail with the specified error.
592
595
  *
593
- * This will result in a `FailureExpected`, where the error is tracked at the
596
+ * This will result in a `CauseFail`, where the error is tracked at the
594
597
  * type level.
595
598
  *
596
599
  * @since 3.4.0
597
600
  * @experimental
598
601
  * @category constructors
599
602
  */
600
- const fail = e => fromResult(ResultFail(e));
603
+ const fail = e => fromExit(exitFail(e));
601
604
  /**
602
605
  * Creates a `Micro` effect that will fail with the lazily evaluated error.
603
606
  *
604
- * This will result in a `FailureExpected`, where the error is tracked at the
607
+ * This will result in a `CauseFail`, where the error is tracked at the
605
608
  * type level.
606
609
  *
607
610
  * @since 3.4.0
@@ -609,13 +612,13 @@ const fail = e => fromResult(ResultFail(e));
609
612
  * @category constructors
610
613
  */
611
614
  exports.fail = fail;
612
- const failSync = e => make(function (_env, onResult) {
613
- onResult(ResultFail(e()));
615
+ const failSync = e => make(function (_env, onExit) {
616
+ onExit(exitFail(e()));
614
617
  });
615
618
  /**
616
619
  * Creates a `Micro` effect that will die with the specified error.
617
620
  *
618
- * This will result in a `FailureUnexpected`, where the error is not tracked at
621
+ * This will result in a `CauseDie`, where the error is not tracked at
619
622
  * the type level.
620
623
  *
621
624
  * @since 3.4.0
@@ -623,38 +626,38 @@ const failSync = e => make(function (_env, onResult) {
623
626
  * @category constructors
624
627
  */
625
628
  exports.failSync = failSync;
626
- const die = defect => fromResult(ResultFailUnexpected(defect));
629
+ const die = defect => fromExit(exitDie(defect));
627
630
  /**
628
- * Creates a `Micro` effect that will fail with the specified `Failure`.
631
+ * Creates a `Micro` effect that will fail with the specified `MicroCause`.
629
632
  *
630
- * @since 3.4.0
633
+ * @since 3.4.6
631
634
  * @experimental
632
635
  * @category constructors
633
636
  */
634
637
  exports.die = die;
635
- const failWith = failure => fromResult(ResultFailWith(failure));
638
+ const failCause = cause => fromExit(exitFailCause(cause));
636
639
  /**
637
- * Creates a `Micro` effect that will fail with the lazily evaluated `Failure`.
640
+ * Creates a `Micro` effect that will fail with the lazily evaluated `MicroCause`.
638
641
  *
639
- * @since 3.4.0
642
+ * @since 3.4.6
640
643
  * @experimental
641
644
  * @category constructors
642
645
  */
643
- exports.failWith = failWith;
644
- const failWithSync = failure => fromResultSync(() => ResultFailWith(failure()));
646
+ exports.failCause = failCause;
647
+ const failCauseSync = cause => fromExitSync(() => exitFailCause(cause()));
645
648
  /**
646
649
  * Creates a `Micro` effect that will succeed with the lazily evaluated value.
647
650
  *
648
651
  * If the evaluation of the value throws an error, the effect will fail with
649
- * `FailureUnexpected`.
652
+ * `CauseDie`.
650
653
  *
651
654
  * @since 3.4.0
652
655
  * @experimental
653
656
  * @category constructors
654
657
  */
655
- exports.failWithSync = failWithSync;
656
- const sync = evaluate => make(function (_env, onResult) {
657
- onResult(ResultSuccess(evaluate()));
658
+ exports.failCauseSync = failCauseSync;
659
+ const sync = evaluate => make(function (_env, onExit) {
660
+ onExit(exitSucceed(evaluate()));
658
661
  });
659
662
  /**
660
663
  * Converts an `Option` into a `Micro` effect, that will fail with
@@ -666,8 +669,8 @@ const sync = evaluate => make(function (_env, onResult) {
666
669
  * @category constructors
667
670
  */
668
671
  exports.sync = sync;
669
- const fromOption = option => make(function (_env, onResult) {
670
- onResult(option._tag === "Some" ? ResultSuccess(option.value) : ResultFail(new NoSuchElementException({})));
672
+ const fromOption = option => make(function (_env, onExit) {
673
+ onExit(option._tag === "Some" ? exitSucceed(option.value) : exitFail(new NoSuchElementException({})));
671
674
  });
672
675
  /**
673
676
  * Converts an `Either` into a `Micro` effect, that will fail with the left side
@@ -679,8 +682,8 @@ const fromOption = option => make(function (_env, onResult) {
679
682
  * @category constructors
680
683
  */
681
684
  exports.fromOption = fromOption;
682
- const fromEither = either => make(function (_env, onResult) {
683
- onResult(either._tag === "Right" ? either : ResultFail(either.left));
685
+ const fromEither = either => make(function (_env, onExit) {
686
+ onExit(either._tag === "Right" ? either : exitFail(either.left));
684
687
  });
685
688
  /**
686
689
  * Lazily creates a `Micro` effect from the given side-effect.
@@ -690,8 +693,8 @@ const fromEither = either => make(function (_env, onResult) {
690
693
  * @category constructors
691
694
  */
692
695
  exports.fromEither = fromEither;
693
- const suspend = evaluate => make(function (env, onResult) {
694
- evaluate()[runSymbol](env, onResult);
696
+ const suspend = evaluate => make(function (env, onExit) {
697
+ evaluate()[runSymbol](env, onExit);
695
698
  });
696
699
  exports.suspend = suspend;
697
700
  const void_ = exports.void = /*#__PURE__*/succeed(void 0);
@@ -706,16 +709,16 @@ const void_ = exports.void = /*#__PURE__*/succeed(void 0);
706
709
  * @experimental
707
710
  * @category constructors
708
711
  */
709
- const async = register => make(function (env, onResult) {
712
+ const async = register => make(function (env, onExit) {
710
713
  let resumed = false;
711
714
  const controller = register.length > 1 ? new AbortController() : undefined;
712
715
  const signal = envGet(env, currentAbortSignal);
713
716
  let cleanup = undefined;
714
717
  function onAbort() {
715
718
  if (cleanup) {
716
- resume(uninterruptible(andThen(cleanup, fromResult(ResultAborted))));
719
+ resume(uninterruptible(andThen(cleanup, fromExit(exitInterrupt))));
717
720
  } else {
718
- resume(fromResult(ResultAborted));
721
+ resume(fromExit(exitInterrupt));
719
722
  }
720
723
  if (controller !== undefined) {
721
724
  controller.abort();
@@ -727,24 +730,24 @@ const async = register => make(function (env, onResult) {
727
730
  }
728
731
  resumed = true;
729
732
  signal.removeEventListener("abort", onAbort);
730
- effect[runSymbol](env, onResult);
733
+ effect[runSymbol](env, onExit);
731
734
  }
732
735
  cleanup = controller === undefined ? register(resume) : register(resume, controller.signal);
733
736
  if (resumed) return;
734
737
  signal.addEventListener("abort", onAbort);
735
738
  });
736
739
  exports.async = async;
737
- const try_ = options => make(function (_env, onResult) {
740
+ const try_ = options => make(function (_env, onExit) {
738
741
  try {
739
- onResult(ResultSuccess(options.try()));
742
+ onExit(exitSucceed(options.try()));
740
743
  } catch (err) {
741
- onResult(ResultFail(options.catch(err)));
744
+ onExit(exitFail(options.catch(err)));
742
745
  }
743
746
  });
744
747
  exports.try = try_;
745
748
  /**
746
749
  * Wrap a `Promise` into a `Micro` effect. Any errors will result in a
747
- * `FailureUnexpected`.
750
+ * `CauseDie`.
748
751
  *
749
752
  * @since 3.4.0
750
753
  * @experimental
@@ -807,8 +810,8 @@ const yieldAdd = task => {
807
810
  * @experimental
808
811
  * @category constructors
809
812
  */
810
- const yieldNow = exports.yieldNow = /*#__PURE__*/make(function (_env, onResult) {
811
- yieldAdd(() => onResult(resultVoid));
813
+ const yieldNow = exports.yieldNow = /*#__PURE__*/make(function (_env, onExit) {
814
+ yieldAdd(() => onExit(exitVoid));
812
815
  });
813
816
  /**
814
817
  * Flush any yielded effects that are waiting to be executed.
@@ -839,7 +842,7 @@ const never = exports.never = /*#__PURE__*/async(function () {
839
842
  * @experimental
840
843
  * @category constructors
841
844
  */
842
- const gen = (...args) => make(function (env, onResult) {
845
+ const gen = (...args) => make(function (env, onExit) {
843
846
  const iterator = args.length === 1 ? args[0]() : args[1].call(args[0]);
844
847
  let running = false;
845
848
  let value = undefined;
@@ -850,21 +853,21 @@ const gen = (...args) => make(function (env, onResult) {
850
853
  while (shouldContinue) {
851
854
  const result = iterator.next(value);
852
855
  if (result.done) {
853
- return onResult(ResultSuccess(result.value));
856
+ return onExit(exitSucceed(result.value));
854
857
  }
855
858
  shouldContinue = false;
856
- (0, _Utils.yieldWrapGet)(result.value)[runSymbol](env, function (result) {
857
- if (result._tag === "Left") {
858
- onResult(result);
859
+ (0, _Utils.yieldWrapGet)(result.value)[runSymbol](env, function (exit) {
860
+ if (exit._tag === "Left") {
861
+ onExit(exit);
859
862
  } else {
860
863
  shouldContinue = true;
861
- value = result.right;
864
+ value = exit.right;
862
865
  if (!running) run();
863
866
  }
864
867
  });
865
868
  }
866
869
  } catch (err) {
867
- onResult(ResultFailUnexpected(err));
870
+ onExit(exitDie(err));
868
871
  }
869
872
  running = false;
870
873
  }
@@ -881,8 +884,8 @@ const gen = (...args) => make(function (env, onResult) {
881
884
  * @category mapping & sequencing
882
885
  */
883
886
  exports.gen = gen;
884
- const flatten = self => make(function (env, onResult) {
885
- self[runSymbol](env, result => result._tag === "Left" ? onResult(result) : result.right[runSymbol](env, onResult));
887
+ const flatten = self => make(function (env, onExit) {
888
+ self[runSymbol](env, exit => exit._tag === "Left" ? onExit(exit) : exit.right[runSymbol](env, onExit));
886
889
  });
887
890
  /**
888
891
  * Transforms the success value of the `Micro` effect with the specified
@@ -893,9 +896,9 @@ const flatten = self => make(function (env, onResult) {
893
896
  * @category mapping & sequencing
894
897
  */
895
898
  exports.flatten = flatten;
896
- const map = exports.map = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => make(function (env, onResult) {
897
- self[runSymbol](env, function (result) {
898
- onResult(result._tag === "Left" ? result : ResultSuccess(f(result.right)));
899
+ const map = exports.map = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => make(function (env, onExit) {
900
+ self[runSymbol](env, function (exit) {
901
+ onExit(exit._tag === "Left" ? exit : exitSucceed(f(exit.right)));
899
902
  });
900
903
  }));
901
904
  /**
@@ -924,12 +927,12 @@ const asSome = self => map(self, Option.some);
924
927
  * @category mapping & sequencing
925
928
  */
926
929
  exports.asSome = asSome;
927
- const flatMap = exports.flatMap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => make(function (env, onResult) {
928
- self[runSymbol](env, function (result) {
929
- if (result._tag === "Left") {
930
- return onResult(result);
930
+ const flatMap = exports.flatMap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => make(function (env, onExit) {
931
+ self[runSymbol](env, function (exit) {
932
+ if (exit._tag === "Left") {
933
+ return onExit(exit);
931
934
  }
932
- f(result.right)[runSymbol](env, onResult);
935
+ f(exit.right)[runSymbol](env, onExit);
933
936
  });
934
937
  }));
935
938
  /**
@@ -939,7 +942,7 @@ const flatMap = exports.flatMap = /*#__PURE__*/(0, _Function.dual)(2, (self, f)
939
942
  * @experimental
940
943
  * @category mapping & sequencing
941
944
  */
942
- const flip = self => matchMicro(self, {
945
+ const flip = self => matchEffect(self, {
943
946
  onFailure: succeed,
944
947
  onSuccess: fail
945
948
  });
@@ -955,18 +958,18 @@ const flip = self => matchMicro(self, {
955
958
  * @category mapping & sequencing
956
959
  */
957
960
  exports.flip = flip;
958
- const andThen = exports.andThen = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => make(function (env, onResult) {
959
- self[runSymbol](env, function (result) {
960
- if (result._tag === "Left") {
961
- return onResult(result);
961
+ const andThen = exports.andThen = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => make(function (env, onExit) {
962
+ self[runSymbol](env, function (exit) {
963
+ if (exit._tag === "Left") {
964
+ return onExit(exit);
962
965
  } else if (envGet(env, currentAbortSignal).aborted) {
963
- return onResult(ResultAborted);
966
+ return onExit(exitInterrupt);
964
967
  }
965
- const value = isMicro(f) ? f : typeof f === "function" ? f(result.right) : f;
968
+ const value = isMicro(f) ? f : typeof f === "function" ? f(exit.right) : f;
966
969
  if (isMicro(value)) {
967
- value[runSymbol](env, onResult);
970
+ value[runSymbol](env, onExit);
968
971
  } else {
969
- onResult(ResultSuccess(value));
972
+ onExit(exitSucceed(value));
970
973
  }
971
974
  });
972
975
  }));
@@ -979,23 +982,23 @@ const andThen = exports.andThen = /*#__PURE__*/(0, _Function.dual)(2, (self, f)
979
982
  * @experimental
980
983
  * @category mapping & sequencing
981
984
  */
982
- const tap = exports.tap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => make(function (env, onResult) {
983
- self[runSymbol](env, function (selfResult) {
984
- if (selfResult._tag === "Left") {
985
- return onResult(selfResult);
985
+ const tap = exports.tap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => make(function (env, onExit) {
986
+ self[runSymbol](env, function (selfExit) {
987
+ if (selfExit._tag === "Left") {
988
+ return onExit(selfExit);
986
989
  } else if (envGet(env, currentAbortSignal).aborted) {
987
- return onResult(ResultAborted);
990
+ return onExit(exitInterrupt);
988
991
  }
989
- const value = isMicro(f) ? f : typeof f === "function" ? f(selfResult.right) : f;
992
+ const value = isMicro(f) ? f : typeof f === "function" ? f(selfExit.right) : f;
990
993
  if (isMicro(value)) {
991
- value[runSymbol](env, function (tapResult) {
992
- if (tapResult._tag === "Left") {
993
- return onResult(tapResult);
994
+ value[runSymbol](env, function (tapExit) {
995
+ if (tapExit._tag === "Left") {
996
+ return onExit(tapExit);
994
997
  }
995
- onResult(selfResult);
998
+ onExit(selfExit);
996
999
  });
997
1000
  } else {
998
- onResult(selfResult);
1001
+ onExit(selfExit);
999
1002
  }
1000
1003
  });
1001
1004
  }));
@@ -1008,27 +1011,27 @@ const tap = exports.tap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => make(
1008
1011
  */
1009
1012
  const asVoid = self => map(self, _ => void 0);
1010
1013
  /**
1011
- * Access the `Result` of the given `Micro` effect.
1014
+ * Access the `MicroExit` of the given `Micro` effect.
1012
1015
  *
1013
- * @since 3.4.0
1016
+ * @since 3.4.6
1014
1017
  * @experimental
1015
1018
  * @category mapping & sequencing
1016
1019
  */
1017
1020
  exports.asVoid = asVoid;
1018
- const asResult = self => make(function (env, onResult) {
1019
- self[runSymbol](env, function (result) {
1020
- onResult(ResultSuccess(result));
1021
+ const exit = self => make(function (env, onExit) {
1022
+ self[runSymbol](env, function (exit) {
1023
+ onExit(exitSucceed(exit));
1021
1024
  });
1022
1025
  });
1023
1026
  /**
1024
- * Replace the error type of the given `Micro` with the full `Failure` object.
1027
+ * Replace the error type of the given `Micro` with the full `MicroCause` object.
1025
1028
  *
1026
1029
  * @since 3.4.0
1027
1030
  * @experimental
1028
1031
  * @category mapping & sequencing
1029
1032
  */
1030
- exports.asResult = asResult;
1031
- const sandbox = self => catchFailure(self, failure => fail(failure));
1033
+ exports.exit = exit;
1034
+ const sandbox = self => catchAllCause(self, cause => fail(cause));
1032
1035
  exports.sandbox = sandbox;
1033
1036
  function forkSignal(env) {
1034
1037
  const controller = new AbortController();
@@ -1054,25 +1057,25 @@ function forkSignal(env) {
1054
1057
  * @experimental
1055
1058
  * @category sequencing
1056
1059
  */
1057
- const raceAll = all => make(function (env, onResult) {
1060
+ const raceAll = all => make(function (env, onExit) {
1058
1061
  const [envWithSignal, onAbort] = forkSignal(env);
1059
1062
  const effects = Array.from(all);
1060
1063
  let len = effects.length;
1061
1064
  let index = 0;
1062
1065
  let done = 0;
1063
- let result = undefined;
1064
- const failures = [];
1065
- function onDone(result_) {
1066
+ let exit = undefined;
1067
+ const causes = [];
1068
+ function onDone(exit_) {
1066
1069
  done++;
1067
- if (result_._tag === "Right" && result === undefined) {
1070
+ if (exit_._tag === "Right" && exit === undefined) {
1068
1071
  len = index;
1069
- result = result_;
1072
+ exit = exit_;
1070
1073
  onAbort();
1071
- } else if (result_._tag === "Left") {
1072
- failures.push(result_.left);
1074
+ } else if (exit_._tag === "Left") {
1075
+ causes.push(exit_.left);
1073
1076
  }
1074
1077
  if (done >= len) {
1075
- onResult(result ?? Either.left(failures[0]));
1078
+ onExit(exit ?? Either.left(causes[0]));
1076
1079
  }
1077
1080
  }
1078
1081
  for (; index < len; index++) {
@@ -1089,23 +1092,23 @@ const raceAll = all => make(function (env, onResult) {
1089
1092
  * @category sequencing
1090
1093
  */
1091
1094
  exports.raceAll = raceAll;
1092
- const raceAllFirst = all => make(function (env, onResult) {
1095
+ const raceAllFirst = all => make(function (env, onExit) {
1093
1096
  const [envWithSignal, onAbort] = forkSignal(env);
1094
1097
  const effects = Array.from(all);
1095
1098
  let len = effects.length;
1096
1099
  let index = 0;
1097
1100
  let done = 0;
1098
- let result = undefined;
1099
- const failures = [];
1100
- function onDone(result_) {
1101
+ let exit = undefined;
1102
+ const causes = [];
1103
+ function onDone(exit_) {
1101
1104
  done++;
1102
- if (result === undefined) {
1105
+ if (exit === undefined) {
1103
1106
  len = index;
1104
- result = result_;
1107
+ exit = exit_;
1105
1108
  onAbort();
1106
1109
  }
1107
1110
  if (done >= len) {
1108
- onResult(result ?? Either.left(failures[0]));
1111
+ onExit(exit ?? Either.left(causes[0]));
1109
1112
  }
1110
1113
  }
1111
1114
  for (; index < len; index++) {
@@ -1166,7 +1169,7 @@ const zipWith = exports.zipWith = /*#__PURE__*/(0, _Function.dual)(args => isMic
1166
1169
  // ----------------------------------------------------------------------------
1167
1170
  /**
1168
1171
  * Filter the specified effect with the provided function, failing with specified
1169
- * `Failure` if the predicate fails.
1172
+ * `MicroCause` if the predicate fails.
1170
1173
  *
1171
1174
  * In addition to the filtering capabilities discussed earlier, you have the option to further
1172
1175
  * refine and narrow down the type of the success channel by providing a
@@ -1175,7 +1178,7 @@ const zipWith = exports.zipWith = /*#__PURE__*/(0, _Function.dual)(args => isMic
1175
1178
  * @experimental
1176
1179
  * @category filtering & conditionals
1177
1180
  */
1178
- const filterOrFailWith = exports.filterOrFailWith = /*#__PURE__*/(0, _Function.dual)(args => isMicro(args[0]), (self, refinement, orFailWith) => flatMap(self, a => refinement(a) ? succeed(a) : failWith(orFailWith(a))));
1181
+ const filterOrFailCause = exports.filterOrFailCause = /*#__PURE__*/(0, _Function.dual)(args => isMicro(args[0]), (self, refinement, orFailWith) => flatMap(self, a => refinement(a) ? succeed(a) : failCause(orFailWith(a))));
1179
1182
  /**
1180
1183
  * Filter the specified effect with the provided function, failing with specified
1181
1184
  * error if the predicate fails.
@@ -1203,34 +1206,34 @@ const when = exports.when = /*#__PURE__*/(0, _Function.dual)(2, (self, condition
1203
1206
  * Repeat the given `Micro` using the provided options.
1204
1207
  *
1205
1208
  * The `while` predicate will be checked after each iteration, and can use the
1206
- * fall `Result` of the effect to determine if the repetition should continue.
1209
+ * fall `MicroExit` of the effect to determine if the repetition should continue.
1207
1210
  *
1208
- * @since 3.4.0
1211
+ * @since 3.4.6
1209
1212
  * @experimental
1210
1213
  * @category repetition
1211
1214
  */
1212
- const repeatResult = exports.repeatResult = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => make(function (env, onResult) {
1213
- const startedAt = options.delay ? Date.now() : 0;
1215
+ const repeatExit = exports.repeatExit = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => make(function (env, onExit) {
1216
+ const startedAt = options.schedule ? Date.now() : 0;
1214
1217
  let attempt = 0;
1215
- self[runSymbol](env, function loop(result) {
1216
- if (options.while !== undefined && !options.while(result)) {
1217
- return onResult(result);
1218
+ self[runSymbol](env, function loop(exit) {
1219
+ if (options.while !== undefined && !options.while(exit)) {
1220
+ return onExit(exit);
1218
1221
  } else if (options.times !== undefined && attempt >= options.times) {
1219
- return onResult(result);
1222
+ return onExit(exit);
1220
1223
  }
1221
1224
  attempt++;
1222
1225
  let delayEffect = yieldNow;
1223
- if (options.delay !== undefined) {
1226
+ if (options.schedule !== undefined) {
1224
1227
  const elapsed = Date.now() - startedAt;
1225
- const duration = options.delay(attempt, elapsed);
1228
+ const duration = options.schedule(attempt, elapsed);
1226
1229
  if (Option.isNone(duration)) {
1227
- return onResult(result);
1230
+ return onExit(exit);
1228
1231
  }
1229
1232
  delayEffect = sleep(duration.value);
1230
1233
  }
1231
- delayEffect[runSymbol](env, function (result) {
1232
- if (result._tag === "Left") {
1233
- return onResult(result);
1234
+ delayEffect[runSymbol](env, function (exit) {
1235
+ if (exit._tag === "Left") {
1236
+ return onExit(exit);
1234
1237
  }
1235
1238
  self[runSymbol](env, loop);
1236
1239
  });
@@ -1244,9 +1247,9 @@ const repeatResult = exports.repeatResult = /*#__PURE__*/(0, _Function.dual)(2,
1244
1247
  * @experimental
1245
1248
  * @category repetition
1246
1249
  */
1247
- const repeat = exports.repeat = /*#__PURE__*/(0, _Function.dual)(args => isMicro(args[0]), (self, options) => repeatResult(self, {
1250
+ const repeat = exports.repeat = /*#__PURE__*/(0, _Function.dual)(args => isMicro(args[0]), (self, options) => repeatExit(self, {
1248
1251
  ...options,
1249
- while: result => result._tag === "Right" && (options?.while === undefined || options.while(result.right))
1252
+ while: exit => exit._tag === "Right" && (options?.while === undefined || options.while(exit.right))
1250
1253
  }));
1251
1254
  /**
1252
1255
  * Repeat the given `Micro` effect forever, only stopping if the effect fails.
@@ -1257,130 +1260,159 @@ const repeat = exports.repeat = /*#__PURE__*/(0, _Function.dual)(args => isMicro
1257
1260
  */
1258
1261
  const forever = self => repeat(self);
1259
1262
  /**
1260
- * Create a `DelayFn` that will generate a duration with an exponential backoff.
1263
+ * Create a `MicroSchedule` that will stop repeating after the specified number
1264
+ * of attempts.
1261
1265
  *
1262
- * @since 3.4.0
1266
+ * @since 3.4.6
1263
1267
  * @experimental
1264
- * @category delay fn
1268
+ * @category scheduling
1265
1269
  */
1266
1270
  exports.forever = forever;
1267
- const delayExponential = (baseMillis, factor = 2) => attempt => Option.some(attempt ** factor * baseMillis);
1271
+ const scheduleRecurs = n => attempt => attempt <= n ? Option.some(0) : Option.none();
1268
1272
  /**
1269
- * Create a `DelayFn` that will generate a duration with fixed intervals.
1273
+ * Create a `MicroSchedule` that will generate a constant delay.
1270
1274
  *
1271
- * @since 3.4.0
1275
+ * @since 3.4.6
1272
1276
  * @experimental
1273
- * @category delay fn
1277
+ * @category scheduling
1274
1278
  */
1275
- exports.delayExponential = delayExponential;
1276
- const delaySpaced = millis => _ => Option.some(millis);
1279
+ exports.scheduleRecurs = scheduleRecurs;
1280
+ const scheduleSpaced = millis => () => Option.some(millis);
1277
1281
  /**
1278
- * Transform a `DelayFn` to one that will have a duration that will never exceed
1282
+ * Create a `MicroSchedule` that will generate a delay with an exponential backoff.
1283
+ *
1284
+ * @since 3.4.6
1285
+ * @experimental
1286
+ * @category scheduling
1287
+ */
1288
+ exports.scheduleSpaced = scheduleSpaced;
1289
+ const scheduleExponential = (baseMillis, factor = 2) => attempt => Option.some(Math.pow(factor, attempt) * baseMillis);
1290
+ /**
1291
+ * Returns a new `MicroSchedule` with an added calculated delay to each delay
1292
+ * returned by this schedule.
1293
+ *
1294
+ * @since 3.4.6
1295
+ * @experimental
1296
+ * @category scheduling
1297
+ */
1298
+ exports.scheduleExponential = scheduleExponential;
1299
+ const scheduleAddDelay = exports.scheduleAddDelay = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => (attempt, elapsed) => Option.map(self(attempt, elapsed), duration => duration + f()));
1300
+ /**
1301
+ * Transform a `MicroSchedule` to one that will have a delay that will never exceed
1279
1302
  * the specified maximum.
1280
1303
  *
1281
- * @since 3.4.0
1304
+ * @since 3.4.6
1282
1305
  * @experimental
1283
- * @category delay fn
1306
+ * @category scheduling
1284
1307
  */
1285
- exports.delaySpaced = delaySpaced;
1286
- const delayWithMax = exports.delayWithMax = /*#__PURE__*/(0, _Function.dual)(2, (self, max) => (attempt, elapsed) => Option.map(self(attempt, elapsed), duration => Math.min(duration, max)));
1308
+ const scheduleWithMaxDelay = exports.scheduleWithMaxDelay = /*#__PURE__*/(0, _Function.dual)(2, (self, max) => (attempt, elapsed) => Option.map(self(attempt, elapsed), duration => Math.min(duration, max)));
1287
1309
  /**
1288
- * Transform a `DelayFn` to one that will stop repeating after the specified
1310
+ * Transform a `MicroSchedule` to one that will stop repeating after the specified
1289
1311
  * amount of time.
1290
1312
  *
1291
- * @since 3.4.0
1313
+ * @since 3.4.6
1292
1314
  * @experimental
1293
- * @category delay fn
1315
+ * @category scheduling
1294
1316
  */
1295
- const delayWithMaxElapsed = exports.delayWithMaxElapsed = /*#__PURE__*/(0, _Function.dual)(2, (self, max) => (attempt, elapsed) => elapsed < max ? self(attempt, elapsed) : Option.none());
1317
+ const scheduleWithMaxElapsed = exports.scheduleWithMaxElapsed = /*#__PURE__*/(0, _Function.dual)(2, (self, max) => (attempt, elapsed) => elapsed < max ? self(attempt, elapsed) : Option.none());
1296
1318
  /**
1297
- * Transform a `DelayFn` to one that will stop repeating after the specified
1298
- * number of attempts.
1319
+ * Combines two `MicroSchedule`s, by recurring if either schedule wants to
1320
+ * recur, using the minimum of the two durations between recurrences.
1299
1321
  *
1300
- * @since 3.4.0
1322
+ * @since 3.4.6
1301
1323
  * @experimental
1302
- * @category delay fn
1324
+ * @category scheduling
1303
1325
  */
1304
- const delayWithRecurs = exports.delayWithRecurs = /*#__PURE__*/(0, _Function.dual)(2, (self, n) => (attempt, elapsed) => Option.filter(self(attempt, elapsed), () => attempt <= n));
1326
+ const scheduleUnion = exports.scheduleUnion = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => (attempt, elapsed) => Option.zipWith(self(attempt, elapsed), that(attempt, elapsed), (d1, d2) => Math.min(d1, d2)));
1327
+ /**
1328
+ * Combines two `MicroSchedule`s, by recurring only if both schedules want to
1329
+ * recur, using the maximum of the two durations between recurrences.
1330
+ *
1331
+ * @since 3.4.6
1332
+ * @experimental
1333
+ * @category scheduling
1334
+ */
1335
+ const scheduleIntersect = exports.scheduleIntersect = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => (attempt, elapsed) => Option.zipWith(self(attempt, elapsed), that(attempt, elapsed), (d1, d2) => Math.max(d1, d2)));
1305
1336
  // ----------------------------------------------------------------------------
1306
1337
  // error handling
1307
1338
  // ----------------------------------------------------------------------------
1308
1339
  /**
1309
- * Catch the full `Failure` object of the given `Micro` effect, allowing you to
1310
- * recover from any kind of failure.
1340
+ * Catch the full `MicroCause` object of the given `Micro` effect, allowing you to
1341
+ * recover from any kind of cause.
1311
1342
  *
1312
- * @since 3.4.0
1343
+ * @since 3.4.6
1313
1344
  * @experimental
1314
1345
  * @category error handling
1315
1346
  */
1316
- const catchFailure = exports.catchFailure = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchFailureIf(self, _Function.constTrue, f));
1347
+ const catchAllCause = exports.catchAllCause = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchCauseIf(self, _Function.constTrue, f));
1317
1348
  /**
1318
- * Selectively catch a `Failure` object of the given `Micro` effect,
1349
+ * Selectively catch a `MicroCause` object of the given `Micro` effect,
1319
1350
  * using the provided predicate to determine if the failure should be caught.
1320
1351
  *
1321
- * @since 3.4.0
1352
+ * @since 3.4.6
1322
1353
  * @experimental
1323
1354
  * @category error handling
1324
1355
  */
1325
- const catchFailureIf = exports.catchFailureIf = /*#__PURE__*/(0, _Function.dual)(3, (self, refinement, f) => make(function (env, onResult) {
1326
- self[runSymbol](env, function (result) {
1327
- if (result._tag === "Right" || !refinement(result.left)) {
1328
- return onResult(result);
1356
+ const catchCauseIf = exports.catchCauseIf = /*#__PURE__*/(0, _Function.dual)(3, (self, predicate, f) => make(function (env, onExit) {
1357
+ self[runSymbol](env, function (exit) {
1358
+ if (exit._tag === "Right" || !predicate(exit.left)) {
1359
+ onExit(exit);
1360
+ } else {
1361
+ f(exit.left)[runSymbol](env, onExit);
1329
1362
  }
1330
- f(result.left)[runSymbol](env, onResult);
1331
1363
  });
1332
1364
  }));
1333
1365
  /**
1334
1366
  * Catch the error of the given `Micro` effect, allowing you to recover from it.
1335
1367
  *
1336
- * It only catches expected (`FailureExpected`) errors.
1368
+ * It only catches expected (`MicroCause.Fail`) errors.
1337
1369
  *
1338
- * @since 3.4.0
1370
+ * @since 3.4.6
1339
1371
  * @experimental
1340
1372
  * @category error handling
1341
1373
  */
1342
- const catchExpected = exports.catchExpected = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchFailureIf(self, failureIsExpected, failure => f(failure.error)));
1374
+ const catchAll = exports.catchAll = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchAllCause(self, cause => causeIsFail(cause) ? f(cause.error) : failCause(cause)));
1343
1375
  /**
1344
1376
  * Catch any unexpected errors of the given `Micro` effect, allowing you to recover from them.
1345
1377
  *
1346
- * @since 3.4.0
1378
+ * @since 3.4.6
1347
1379
  * @experimental
1348
1380
  * @category error handling
1349
1381
  */
1350
- const catchUnexpected = exports.catchUnexpected = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchFailureIf(self, failureIsUnexpected, failure => f(failure.defect)));
1382
+ const catchAllDefect = exports.catchAllDefect = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchCauseIf(self, causeIsDie, die => f(die.defect)));
1351
1383
  /**
1352
- * Perform a side effect using the full `Failure` object of the given `Micro`.
1384
+ * Perform a side effect using the full `MicroCause` object of the given `Micro`.
1353
1385
  *
1354
- * @since 3.4.0
1386
+ * @since 3.4.6
1355
1387
  * @experimental
1356
1388
  * @category error handling
1357
1389
  */
1358
- const tapFailure = exports.tapFailure = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => tapFailureIf(self, _Function.constTrue, f));
1390
+ const tapErrorCause = exports.tapErrorCause = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => tapErrorCauseIf(self, _Function.constTrue, f));
1359
1391
  /**
1360
- * Perform a side effect using if a `Failure` object matches the specified
1392
+ * Perform a side effect using if a `MicroCause` object matches the specified
1361
1393
  * predicate.
1362
1394
  *
1363
1395
  * @since 3.4.0
1364
1396
  * @experimental
1365
1397
  * @category error handling
1366
1398
  */
1367
- const tapFailureIf = exports.tapFailureIf = /*#__PURE__*/(0, _Function.dual)(3, (self, refinement, f) => catchFailureIf(self, refinement, failure => andThen(f(failure), failWith(failure))));
1399
+ const tapErrorCauseIf = exports.tapErrorCauseIf = /*#__PURE__*/(0, _Function.dual)(3, (self, refinement, f) => catchCauseIf(self, refinement, cause => andThen(f(cause), failCause(cause))));
1368
1400
  /**
1369
1401
  * Perform a side effect from expected errors of the given `Micro`.
1370
1402
  *
1371
- * @since 3.4.0
1403
+ * @since 3.4.6
1372
1404
  * @experimental
1373
1405
  * @category error handling
1374
1406
  */
1375
- const tapExpected = exports.tapExpected = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => tapFailureIf(self, failureIsExpected, failure => f(failure.error)));
1407
+ const tapError = exports.tapError = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => tapErrorCauseIf(self, causeIsFail, fail => f(fail.error)));
1376
1408
  /**
1377
1409
  * Perform a side effect from unexpected errors of the given `Micro`.
1378
1410
  *
1379
- * @since 3.4.0
1411
+ * @since 3.4.6
1380
1412
  * @experimental
1381
1413
  * @category error handling
1382
1414
  */
1383
- const tapUnexpected = exports.tapUnexpected = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => tapFailureIf(self, failureIsUnexpected, failure => f(failure.defect)));
1415
+ const tapDefect = exports.tapDefect = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => tapErrorCauseIf(self, causeIsDie, die => f(die.defect)));
1384
1416
  /**
1385
1417
  * Catch any expected errors that match the specified predicate.
1386
1418
  *
@@ -1388,7 +1420,7 @@ const tapUnexpected = exports.tapUnexpected = /*#__PURE__*/(0, _Function.dual)(2
1388
1420
  * @experimental
1389
1421
  * @category error handling
1390
1422
  */
1391
- const catchIf = exports.catchIf = /*#__PURE__*/(0, _Function.dual)(3, (self, predicate, f) => catchFailureIf(self, f => failureIsExpected(f) && predicate(f.error), failure => f(failure.error)));
1423
+ const catchIf = exports.catchIf = /*#__PURE__*/(0, _Function.dual)(3, (self, predicate, f) => catchCauseIf(self, f => causeIsFail(f) && predicate(f.error), fail => f(fail.error)));
1392
1424
  /**
1393
1425
  * Recovers from the specified tagged error.
1394
1426
  *
@@ -1398,13 +1430,13 @@ const catchIf = exports.catchIf = /*#__PURE__*/(0, _Function.dual)(3, (self, pre
1398
1430
  */
1399
1431
  const catchTag = exports.catchTag = /*#__PURE__*/(0, _Function.dual)(3, (self, k, f) => catchIf(self, (0, _Predicate.isTagged)(k), f));
1400
1432
  /**
1401
- * Transform the full `Failure` object of the given `Micro` effect.
1433
+ * Transform the full `MicroCause` object of the given `Micro` effect.
1402
1434
  *
1403
- * @since 3.4.0
1435
+ * @since 3.4.6
1404
1436
  * @experimental
1405
1437
  * @category error handling
1406
1438
  */
1407
- const mapFailure = exports.mapFailure = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchFailure(self, failure => failWith(f(failure))));
1439
+ const mapErrorCause = exports.mapErrorCause = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchAllCause(self, cause => failCause(f(cause))));
1408
1440
  /**
1409
1441
  * Transform any expected errors of the given `Micro` effect.
1410
1442
  *
@@ -1412,7 +1444,7 @@ const mapFailure = exports.mapFailure = /*#__PURE__*/(0, _Function.dual)(2, (sel
1412
1444
  * @experimental
1413
1445
  * @category error handling
1414
1446
  */
1415
- const mapError = exports.mapError = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchExpected(self, error => fail(f(error))));
1447
+ const mapError = exports.mapError = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchAll(self, error => fail(f(error))));
1416
1448
  /**
1417
1449
  * Elevate any expected errors of the given `Micro` effect to unexpected errors,
1418
1450
  * resulting in an error type of `never`.
@@ -1421,7 +1453,7 @@ const mapError = exports.mapError = /*#__PURE__*/(0, _Function.dual)(2, (self, f
1421
1453
  * @experimental
1422
1454
  * @category error handling
1423
1455
  */
1424
- const orDie = self => catchExpected(self, die);
1456
+ const orDie = self => catchAll(self, die);
1425
1457
  /**
1426
1458
  * Recover from all errors by succeeding with the given value.
1427
1459
  *
@@ -1430,7 +1462,7 @@ const orDie = self => catchExpected(self, die);
1430
1462
  * @category error handling
1431
1463
  */
1432
1464
  exports.orDie = orDie;
1433
- const orElseSucceed = exports.orElseSucceed = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchExpected(self, _ => sync(f)));
1465
+ const orElseSucceed = exports.orElseSucceed = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => catchAll(self, _ => sync(f)));
1434
1466
  /**
1435
1467
  * Ignore any expected errors of the given `Micro` effect, returning `void`.
1436
1468
  *
@@ -1438,7 +1470,7 @@ const orElseSucceed = exports.orElseSucceed = /*#__PURE__*/(0, _Function.dual)(2
1438
1470
  * @experimental
1439
1471
  * @category error handling
1440
1472
  */
1441
- const ignore = self => matchMicro(self, {
1473
+ const ignore = self => matchEffect(self, {
1442
1474
  onFailure: _ => void_,
1443
1475
  onSuccess: _ => void_
1444
1476
  });
@@ -1450,8 +1482,8 @@ const ignore = self => matchMicro(self, {
1450
1482
  * @category error handling
1451
1483
  */
1452
1484
  exports.ignore = ignore;
1453
- const ignoreLogged = self => matchMicro(self, {
1454
- onFailure: failure => sync(() => console.error(failure)),
1485
+ const ignoreLogged = self => matchEffect(self, {
1486
+ onFailure: error => sync(() => console.error(error)),
1455
1487
  onSuccess: _ => void_
1456
1488
  });
1457
1489
  /**
@@ -1490,13 +1522,13 @@ const either = self => match(self, {
1490
1522
  * @category error handling
1491
1523
  */
1492
1524
  exports.either = either;
1493
- const retry = exports.retry = /*#__PURE__*/(0, _Function.dual)(args => isMicro(args[0]), (self, options) => repeatResult(self, {
1525
+ const retry = exports.retry = /*#__PURE__*/(0, _Function.dual)(args => isMicro(args[0]), (self, options) => repeatExit(self, {
1494
1526
  ...options,
1495
- while: result => result._tag === "Left" && result.left._tag === "Expected" && (options?.while === undefined || options.while(result.left.error))
1527
+ while: exit => exit._tag === "Left" && exit.left._tag === "Fail" && (options?.while === undefined || options.while(exit.left.error))
1496
1528
  }));
1497
1529
  /**
1498
1530
  * Add a stack trace to any failures that occur in the effect. The trace will be
1499
- * added to the `traces` field of the `Failure` object.
1531
+ * added to the `traces` field of the `MicroCause` object.
1500
1532
  *
1501
1533
  * @since 3.4.0
1502
1534
  * @experimental
@@ -1507,21 +1539,21 @@ const withTrace = function () {
1507
1539
  globalThis.Error.stackTraceLimit = 2;
1508
1540
  const error = new globalThis.Error();
1509
1541
  globalThis.Error.stackTraceLimit = prevLimit;
1510
- function generate(name, failure) {
1542
+ function generate(name, cause) {
1511
1543
  const stack = error.stack;
1512
1544
  if (!stack) {
1513
- return failure;
1545
+ return cause;
1514
1546
  }
1515
1547
  const line = stack.split("\n")[2]?.trim().replace(/^at /, "");
1516
1548
  if (!line) {
1517
- return failure;
1549
+ return cause;
1518
1550
  }
1519
1551
  const lineMatch = line.match(/\((.*)\)$/);
1520
- return failureWithTrace(failure, `at ${name} (${lineMatch ? lineMatch[1] : line})`);
1552
+ return causeWithTrace(cause, `at ${name} (${lineMatch ? lineMatch[1] : line})`);
1521
1553
  }
1522
- const f = name => self => unsafeMakeOptions(function (env, onResult) {
1523
- self[runSymbol](env, function (result) {
1524
- onResult(result._tag === "Left" ? Either.left(generate(name, result.left)) : result);
1554
+ const f = name => self => unsafeMakeOptions(function (env, onExit) {
1555
+ self[runSymbol](env, function (exit) {
1556
+ onExit(exit._tag === "Left" ? Either.left(generate(name, exit.left)) : exit);
1525
1557
  });
1526
1558
  }, false);
1527
1559
  if (arguments.length === 2) {
@@ -1533,37 +1565,37 @@ const withTrace = function () {
1533
1565
  // pattern matching
1534
1566
  // ----------------------------------------------------------------------------
1535
1567
  /**
1536
- * @since 3.4.0
1568
+ * @since 3.4.6
1537
1569
  * @experimental
1538
1570
  * @category pattern matching
1539
1571
  */
1540
1572
  exports.withTrace = withTrace;
1541
- const matchFailureMicro = exports.matchFailureMicro = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => make(function (env, onResult) {
1542
- self[runSymbol](env, function (result) {
1573
+ const matchCauseEffect = exports.matchCauseEffect = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => make(function (env, onExit) {
1574
+ self[runSymbol](env, function (exit) {
1543
1575
  try {
1544
- const next = result._tag === "Left" ? options.onFailure(result.left) : options.onSuccess(result.right);
1545
- next[runSymbol](env, onResult);
1576
+ const next = exit._tag === "Left" ? options.onFailure(exit.left) : options.onSuccess(exit.right);
1577
+ next[runSymbol](env, onExit);
1546
1578
  } catch (err) {
1547
- onResult(ResultFailUnexpected(err));
1579
+ onExit(exitDie(err));
1548
1580
  }
1549
1581
  });
1550
1582
  }));
1551
1583
  /**
1552
- * @since 3.4.0
1584
+ * @since 3.4.6
1553
1585
  * @experimental
1554
1586
  * @category pattern matching
1555
1587
  */
1556
- const matchFailure = exports.matchFailure = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => matchFailureMicro(self, {
1557
- onFailure: failure => sync(() => options.onFailure(failure)),
1588
+ const matchCause = exports.matchCause = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => matchCauseEffect(self, {
1589
+ onFailure: cause => sync(() => options.onFailure(cause)),
1558
1590
  onSuccess: value => sync(() => options.onSuccess(value))
1559
1591
  }));
1560
1592
  /**
1561
- * @since 3.4.0
1593
+ * @since 3.4.6
1562
1594
  * @experimental
1563
1595
  * @category pattern matching
1564
1596
  */
1565
- const matchMicro = exports.matchMicro = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => matchFailureMicro(self, {
1566
- onFailure: failure => failure._tag === "Expected" ? options.onFailure(failure.error) : failWith(failure),
1597
+ const matchEffect = exports.matchEffect = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => matchCauseEffect(self, {
1598
+ onFailure: cause => cause._tag === "Fail" ? options.onFailure(cause.error) : failCause(cause),
1567
1599
  onSuccess: options.onSuccess
1568
1600
  }));
1569
1601
  /**
@@ -1571,7 +1603,7 @@ const matchMicro = exports.matchMicro = /*#__PURE__*/(0, _Function.dual)(2, (sel
1571
1603
  * @experimental
1572
1604
  * @category pattern matching
1573
1605
  */
1574
- const match = exports.match = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => matchMicro(self, {
1606
+ const match = exports.match = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => matchEffect(self, {
1575
1607
  onFailure: error => sync(() => options.onFailure(error)),
1576
1608
  onSuccess: value => sync(() => options.onSuccess(value))
1577
1609
  }));
@@ -1614,6 +1646,21 @@ const delay = exports.delay = /*#__PURE__*/(0, _Function.dual)(2, (self, millis)
1614
1646
  * @category delays & timeouts
1615
1647
  */
1616
1648
  const timeoutOrElse = exports.timeoutOrElse = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => raceFirst(self, andThen(interruptible(sleep(options.duration)), options.onTimeout)));
1649
+ /**
1650
+ * Returns an effect that will timeout this effect, that will fail with a
1651
+ * `TimeoutException` if the timeout elapses before the effect has produced a
1652
+ * value.
1653
+ *
1654
+ * If the timeout elapses, the running effect will be safely interrupted.
1655
+ *
1656
+ * @since 3.4.0
1657
+ * @experimental
1658
+ * @category delays & timeouts
1659
+ */
1660
+ const timeout = exports.timeout = /*#__PURE__*/(0, _Function.dual)(2, (self, millis) => timeoutOrElse(self, {
1661
+ duration: millis,
1662
+ onTimeout: () => fail(new TimeoutException())
1663
+ }));
1617
1664
  /**
1618
1665
  * Returns an effect that will timeout this effect, succeeding with a `None`
1619
1666
  * if the timeout elapses before the effect has produced a value; and `Some` of
@@ -1625,7 +1672,7 @@ const timeoutOrElse = exports.timeoutOrElse = /*#__PURE__*/(0, _Function.dual)(2
1625
1672
  * @experimental
1626
1673
  * @category delays & timeouts
1627
1674
  */
1628
- const timeout = exports.timeout = /*#__PURE__*/(0, _Function.dual)(2, (self, millis) => raceFirst(asSome(self), as(interruptible(sleep(millis)), Option.none())));
1675
+ const timeoutOption = exports.timeoutOption = /*#__PURE__*/(0, _Function.dual)(2, (self, millis) => raceFirst(asSome(self), as(interruptible(sleep(millis)), Option.none())));
1629
1676
  // ----------------------------------------------------------------------------
1630
1677
  // resources & finalization
1631
1678
  // ----------------------------------------------------------------------------
@@ -1641,7 +1688,7 @@ const MicroScopeTypeId = exports.MicroScopeTypeId = /*#__PURE__*/Symbol.for("eff
1641
1688
  * @category resources & finalization
1642
1689
  */
1643
1690
  const MicroScope = exports.MicroScope = /*#__PURE__*/Context.GenericTag("effect/Micro/MicroScope");
1644
- class ScopeImpl {
1691
+ class MicroScopeImpl {
1645
1692
  [MicroScopeTypeId];
1646
1693
  state = {
1647
1694
  _tag: "Open",
@@ -1661,7 +1708,7 @@ class ScopeImpl {
1661
1708
  this.state.finalizers.add(finalizer);
1662
1709
  return void_;
1663
1710
  }
1664
- return finalizer(this.state.result);
1711
+ return finalizer(this.state.exit);
1665
1712
  });
1666
1713
  }
1667
1714
  unsafeRemoveFinalizer(finalizer) {
@@ -1669,28 +1716,28 @@ class ScopeImpl {
1669
1716
  this.state.finalizers.delete(finalizer);
1670
1717
  }
1671
1718
  }
1672
- close(result) {
1719
+ close(microExit) {
1673
1720
  return suspend(() => {
1674
1721
  if (this.state._tag === "Open") {
1675
1722
  const finalizers = Array.from(this.state.finalizers).reverse();
1676
1723
  this.state = {
1677
1724
  _tag: "Closed",
1678
- result
1725
+ exit: microExit
1679
1726
  };
1680
- return flatMap(forEach(finalizers, finalizer => asResult(finalizer(result))), results => asVoid(fromResult(Either.all(results))));
1727
+ return flatMap(forEach(finalizers, finalizer => exit(finalizer(microExit))), exits => asVoid(fromExit(Either.all(exits))));
1681
1728
  }
1682
1729
  return void_;
1683
1730
  });
1684
1731
  }
1685
1732
  get fork() {
1686
1733
  return sync(() => {
1687
- const newScope = new ScopeImpl();
1734
+ const newScope = new MicroScopeImpl();
1688
1735
  if (this.state._tag === "Closed") {
1689
1736
  newScope.state = this.state;
1690
1737
  return newScope;
1691
1738
  }
1692
- function fin(result) {
1693
- return newScope.close(result);
1739
+ function fin(exit) {
1740
+ return newScope.close(exit);
1694
1741
  }
1695
1742
  this.state.finalizers.add(fin);
1696
1743
  newScope.unsafeAddFinalizer(_ => sync(() => this.unsafeRemoveFinalizer(fin)));
@@ -1703,13 +1750,13 @@ class ScopeImpl {
1703
1750
  * @experimental
1704
1751
  * @category resources & finalization
1705
1752
  */
1706
- const scopeMake = exports.scopeMake = /*#__PURE__*/sync(() => new ScopeImpl());
1753
+ const scopeMake = exports.scopeMake = /*#__PURE__*/sync(() => new MicroScopeImpl());
1707
1754
  /**
1708
1755
  * @since 3.4.0
1709
1756
  * @experimental
1710
1757
  * @category resources & finalization
1711
1758
  */
1712
- const scopeUnsafeMake = () => new ScopeImpl();
1759
+ const scopeUnsafeMake = () => new MicroScopeImpl();
1713
1760
  /**
1714
1761
  * Access the current `MicroScope`.
1715
1762
  *
@@ -1736,8 +1783,8 @@ const provideScope = exports.provideScope = /*#__PURE__*/(0, _Function.dual)(2,
1736
1783
  * @category resources & finalization
1737
1784
  */
1738
1785
  const scoped = self => suspend(function () {
1739
- const scope = new ScopeImpl();
1740
- return onResult(provideService(self, MicroScope, scope), result => scope.close(result));
1786
+ const scope = new MicroScopeImpl();
1787
+ return onExit(provideService(self, MicroScope, scope), exit => scope.close(exit));
1741
1788
  });
1742
1789
  /**
1743
1790
  * Create a resource with a cleanup `Micro` effect, ensuring the cleanup is
@@ -1748,7 +1795,7 @@ const scoped = self => suspend(function () {
1748
1795
  * @category resources & finalization
1749
1796
  */
1750
1797
  exports.scoped = scoped;
1751
- const acquireRelease = (acquire, release) => uninterruptible(flatMap(scope, scope => tap(acquire, a => scope.addFinalizer(result => release(a, result)))));
1798
+ const acquireRelease = (acquire, release) => uninterruptible(flatMap(scope, scope => tap(acquire, a => scope.addFinalizer(exit => release(a, exit)))));
1752
1799
  /**
1753
1800
  * Add a finalizer to the current `MicroScope`.
1754
1801
  *
@@ -1760,32 +1807,32 @@ exports.acquireRelease = acquireRelease;
1760
1807
  const addFinalizer = finalizer => flatMap(scope, scope => scope.addFinalizer(finalizer));
1761
1808
  /**
1762
1809
  * When the `Micro` effect is completed, run the given finalizer effect with the
1763
- * `Result` of the executed effect.
1810
+ * `MicroExit` of the executed effect.
1764
1811
  *
1765
- * @since 3.4.0
1812
+ * @since 3.4.6
1766
1813
  * @experimental
1767
1814
  * @category resources & finalization
1768
1815
  */
1769
1816
  exports.addFinalizer = addFinalizer;
1770
- const onResult = exports.onResult = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => onResultIf(self, _Function.constTrue, f));
1817
+ const onExit = exports.onExit = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => onExitIf(self, _Function.constTrue, f));
1771
1818
  /**
1772
1819
  * When the `Micro` effect is completed, run the given finalizer effect if it
1773
1820
  * matches the specified predicate.
1774
1821
  *
1775
- * @since 3.4.0
1822
+ * @since 3.4.6
1776
1823
  * @experimental
1777
1824
  * @category resources & finalization
1778
1825
  */
1779
- const onResultIf = exports.onResultIf = /*#__PURE__*/(0, _Function.dual)(3, (self, refinement, f) => uninterruptibleMask(restore => make(function (env, onResult) {
1780
- restore(self)[runSymbol](env, function (result) {
1781
- if (!refinement(result)) {
1782
- return onResult(result);
1826
+ const onExitIf = exports.onExitIf = /*#__PURE__*/(0, _Function.dual)(3, (self, refinement, f) => uninterruptibleMask(restore => make(function (env, onExit) {
1827
+ restore(self)[runSymbol](env, function (exit) {
1828
+ if (!refinement(exit)) {
1829
+ return onExit(exit);
1783
1830
  }
1784
- f(result)[runSymbol](env, function (finalizerResult) {
1785
- if (finalizerResult._tag === "Left") {
1786
- return onResult(finalizerResult);
1831
+ f(exit)[runSymbol](env, function (finalizerExit) {
1832
+ if (finalizerExit._tag === "Left") {
1833
+ return onExit(finalizerExit);
1787
1834
  }
1788
- onResult(result);
1835
+ onExit(exit);
1789
1836
  });
1790
1837
  });
1791
1838
  })));
@@ -1796,24 +1843,24 @@ const onResultIf = exports.onResultIf = /*#__PURE__*/(0, _Function.dual)(3, (sel
1796
1843
  * @experimental
1797
1844
  * @category resources & finalization
1798
1845
  */
1799
- const ensuring = exports.ensuring = /*#__PURE__*/(0, _Function.dual)(2, (self, finalizer) => onResult(self, _ => finalizer));
1846
+ const ensuring = exports.ensuring = /*#__PURE__*/(0, _Function.dual)(2, (self, finalizer) => onExit(self, _ => finalizer));
1800
1847
  /**
1801
1848
  * When the `Micro` effect fails, run the given finalizer effect with the
1802
- * `Failure` of the executed effect.
1849
+ * `MicroCause` of the executed effect.
1803
1850
  *
1804
- * @since 3.4.0
1851
+ * @since 3.4.6
1805
1852
  * @experimental
1806
1853
  * @category resources & finalization
1807
1854
  */
1808
- const onFailure = exports.onFailure = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => onResultIf(self, resultIsFailure, result => f(result.left)));
1855
+ const onError = exports.onError = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => onExitIf(self, exitIsFailure, exit => f(exit.left)));
1809
1856
  /**
1810
1857
  * If this `Micro` effect is aborted, run the finalizer effect.
1811
1858
  *
1812
- * @since 3.4.0
1859
+ * @since 3.4.6
1813
1860
  * @experimental
1814
1861
  * @category resources & finalization
1815
1862
  */
1816
- const onAbort = exports.onAbort = /*#__PURE__*/(0, _Function.dual)(2, (self, finalizer) => onResultIf(self, resultIsAborted, _ => finalizer));
1863
+ const onInterrupt = exports.onInterrupt = /*#__PURE__*/(0, _Function.dual)(2, (self, finalizer) => onExitIf(self, exitIsInterrupt, _ => finalizer));
1817
1864
  /**
1818
1865
  * Acquire a resource, use it, and then release the resource when the `use`
1819
1866
  * effect has completed.
@@ -1822,22 +1869,22 @@ const onAbort = exports.onAbort = /*#__PURE__*/(0, _Function.dual)(2, (self, fin
1822
1869
  * @experimental
1823
1870
  * @category resources & finalization
1824
1871
  */
1825
- const acquireUseRelease = (acquire, use, release) => uninterruptibleMask(restore => flatMap(acquire, a => flatMap(asResult(restore(use(a))), result => andThen(release(a, result), fromResult(result)))));
1872
+ const acquireUseRelease = (acquire, use, release) => uninterruptibleMask(restore => flatMap(acquire, a => flatMap(exit(restore(use(a))), exit => andThen(release(a, exit), fromExit(exit)))));
1826
1873
  // ----------------------------------------------------------------------------
1827
1874
  // interruption
1828
1875
  // ----------------------------------------------------------------------------
1829
1876
  /**
1830
1877
  * Abort the current `Micro` effect.
1831
1878
  *
1832
- * @since 3.4.0
1879
+ * @since 3.4.6
1833
1880
  * @experimental
1834
1881
  * @category interruption
1835
1882
  */
1836
1883
  exports.acquireUseRelease = acquireUseRelease;
1837
- const abort = exports.abort = /*#__PURE__*/make(function (env, onResult) {
1884
+ const interrupt = exports.interrupt = /*#__PURE__*/make(function (env, onExit) {
1838
1885
  const controller = envGet(env, currentAbortController);
1839
1886
  controller.abort();
1840
- onResult(ResultAborted);
1887
+ onExit(exitInterrupt);
1841
1888
  });
1842
1889
  /**
1843
1890
  * Wrap the given `Micro` effect in an uninterruptible region, preventing the
@@ -1847,13 +1894,13 @@ const abort = exports.abort = /*#__PURE__*/make(function (env, onResult) {
1847
1894
  * @experimental
1848
1895
  * @category interruption
1849
1896
  */
1850
- const uninterruptible = self => unsafeMakeOptions(function (env, onResult) {
1897
+ const uninterruptible = self => unsafeMakeOptions(function (env, onExit) {
1851
1898
  const nextEnv = envMutate(env, function (env) {
1852
1899
  env[currentInterruptible.key] = false;
1853
1900
  env[currentAbortSignal.key] = new AbortController().signal;
1854
1901
  return env;
1855
1902
  });
1856
- self[runSymbol](nextEnv, onResult);
1903
+ self[runSymbol](nextEnv, onExit);
1857
1904
  }, false);
1858
1905
  /**
1859
1906
  * Wrap the given `Micro` effect in an uninterruptible region, preventing the
@@ -1875,7 +1922,7 @@ const uninterruptible = self => unsafeMakeOptions(function (env, onResult) {
1875
1922
  * )
1876
1923
  */
1877
1924
  exports.uninterruptible = uninterruptible;
1878
- const uninterruptibleMask = f => unsafeMakeOptions((env, onResult) => {
1925
+ const uninterruptibleMask = f => unsafeMakeOptions((env, onExit) => {
1879
1926
  const isInterruptible = envGet(env, currentInterruptible);
1880
1927
  const effect = isInterruptible ? f(interruptible) : f(_Function.identity);
1881
1928
  const nextEnv = isInterruptible ? envMutate(env, function (env) {
@@ -1883,7 +1930,7 @@ const uninterruptibleMask = f => unsafeMakeOptions((env, onResult) => {
1883
1930
  env[currentAbortSignal.key] = new AbortController().signal;
1884
1931
  return env;
1885
1932
  }) : env;
1886
- effect[runSymbol](nextEnv, onResult);
1933
+ effect[runSymbol](nextEnv, onExit);
1887
1934
  }, false);
1888
1935
  /**
1889
1936
  * Wrap the given `Micro` effect in an interruptible region, allowing the effect
@@ -1894,7 +1941,7 @@ const uninterruptibleMask = f => unsafeMakeOptions((env, onResult) => {
1894
1941
  * @category interruption
1895
1942
  */
1896
1943
  exports.uninterruptibleMask = uninterruptibleMask;
1897
- const interruptible = self => make((env, onResult) => {
1944
+ const interruptible = self => make((env, onExit) => {
1898
1945
  const isInterruptible = envGet(env, currentInterruptible);
1899
1946
  let newEnv = env;
1900
1947
  if (!isInterruptible) {
@@ -1905,7 +1952,7 @@ const interruptible = self => make((env, onResult) => {
1905
1952
  return env;
1906
1953
  });
1907
1954
  }
1908
- self[runSymbol](newEnv, onResult);
1955
+ self[runSymbol](newEnv, onExit);
1909
1956
  });
1910
1957
  /**
1911
1958
  * Runs all the provided effects in sequence respecting the structure provided in input.
@@ -1947,13 +1994,13 @@ const all = (arg, options) => {
1947
1994
  * @category collecting & elements
1948
1995
  */
1949
1996
  exports.all = all;
1950
- const forEach = (iterable, f, options) => make(function (env, onResult) {
1997
+ const forEach = (iterable, f, options) => make(function (env, onExit) {
1951
1998
  const concurrencyOption = options?.concurrency === "inherit" ? envGet(env, currentConcurrency) : options?.concurrency ?? 1;
1952
1999
  const concurrency = concurrencyOption === "unbounded" ? Number.POSITIVE_INFINITY : Math.max(1, concurrencyOption);
1953
2000
  // abort
1954
2001
  const [envWithSignal, onAbort] = forkSignal(env);
1955
2002
  // iterate
1956
- let failure = undefined;
2003
+ let result = undefined;
1957
2004
  const items = Array.from(iterable);
1958
2005
  let length = items.length;
1959
2006
  const out = options?.discard ? undefined : new Array(length);
@@ -1969,26 +2016,26 @@ const forEach = (iterable, f, options) => make(function (env, onResult) {
1969
2016
  index++;
1970
2017
  inProgress++;
1971
2018
  try {
1972
- f(item, currentIndex)[runSymbol](envWithSignal, function (result) {
1973
- if (result._tag === "Left") {
1974
- if (failure === undefined) {
1975
- failure = result;
2019
+ f(item, currentIndex)[runSymbol](envWithSignal, function (exit) {
2020
+ if (exit._tag === "Left") {
2021
+ if (result === undefined) {
2022
+ result = exit;
1976
2023
  length = index;
1977
2024
  onAbort();
1978
2025
  }
1979
2026
  } else if (out !== undefined) {
1980
- out[currentIndex] = result.right;
2027
+ out[currentIndex] = exit.right;
1981
2028
  }
1982
2029
  doneCount++;
1983
2030
  inProgress--;
1984
2031
  if (doneCount === length) {
1985
- onResult(failure ?? Either.right(out));
2032
+ onExit(result ?? Either.right(out));
1986
2033
  } else if (!pumping && inProgress < concurrency) {
1987
2034
  pump();
1988
2035
  }
1989
2036
  });
1990
2037
  } catch (err) {
1991
- failure = ResultFailUnexpected(err);
2038
+ result = exitDie(err);
1992
2039
  length = index;
1993
2040
  onAbort();
1994
2041
  }
@@ -2010,7 +2057,7 @@ exports.forEach = forEach;
2010
2057
  const filter = (iterable, f, options) => filterMap(iterable, a => map(f(a), pass => {
2011
2058
  pass = options?.negate ? !pass : pass;
2012
2059
  return pass ? Option.some(a) : Option.none();
2013
- }));
2060
+ }), options);
2014
2061
  /**
2015
2062
  * Effectfully filter the elements of the provided iterable.
2016
2063
  *
@@ -2081,7 +2128,7 @@ class HandleImpl {
2081
2128
  parentSignal;
2082
2129
  [HandleTypeId];
2083
2130
  observers = new Set();
2084
- _result = undefined;
2131
+ _exit = undefined;
2085
2132
  _controller;
2086
2133
  isRoot;
2087
2134
  constructor(parentSignal, controller) {
@@ -2090,29 +2137,29 @@ class HandleImpl {
2090
2137
  this.isRoot = controller !== undefined;
2091
2138
  this._controller = controller ?? new AbortController();
2092
2139
  if (!this.isRoot) {
2093
- parentSignal.addEventListener("abort", this.unsafeAbort);
2140
+ parentSignal.addEventListener("abort", this.unsafeInterrupt);
2094
2141
  }
2095
2142
  }
2096
2143
  unsafePoll() {
2097
- return this._result ?? null;
2144
+ return this._exit ?? null;
2098
2145
  }
2099
- unsafeAbort = () => {
2146
+ unsafeInterrupt = () => {
2100
2147
  this._controller.abort();
2101
2148
  };
2102
- emit(result) {
2103
- if (this._result) {
2149
+ emit(exit) {
2150
+ if (this._exit) {
2104
2151
  return;
2105
2152
  }
2106
- this._result = result;
2153
+ this._exit = exit;
2107
2154
  if (!this.isRoot) {
2108
- this.parentSignal.removeEventListener("abort", this.unsafeAbort);
2155
+ this.parentSignal.removeEventListener("abort", this.unsafeInterrupt);
2109
2156
  }
2110
- this.observers.forEach(observer => observer(result));
2157
+ this.observers.forEach(observer => observer(exit));
2111
2158
  this.observers.clear();
2112
2159
  }
2113
2160
  addObserver(observer) {
2114
- if (this._result) {
2115
- return observer(this._result);
2161
+ if (this._exit) {
2162
+ return observer(this._exit);
2116
2163
  }
2117
2164
  this.observers.add(observer);
2118
2165
  }
@@ -2121,12 +2168,12 @@ class HandleImpl {
2121
2168
  }
2122
2169
  get await() {
2123
2170
  return suspend(() => {
2124
- if (this._result) {
2125
- return succeed(this._result);
2171
+ if (this._exit) {
2172
+ return succeed(this._exit);
2126
2173
  }
2127
2174
  return async(resume => {
2128
- function observer(result) {
2129
- resume(succeed(result));
2175
+ function observer(exit) {
2176
+ resume(succeed(exit));
2130
2177
  }
2131
2178
  this.addObserver(observer);
2132
2179
  return sync(() => {
@@ -2136,11 +2183,11 @@ class HandleImpl {
2136
2183
  });
2137
2184
  }
2138
2185
  get join() {
2139
- return flatMap(this.await, fromResult);
2186
+ return flatMap(this.await, fromExit);
2140
2187
  }
2141
- get abort() {
2188
+ get interrupt() {
2142
2189
  return suspend(() => {
2143
- this.unsafeAbort();
2190
+ this.unsafeInterrupt();
2144
2191
  return this.await;
2145
2192
  });
2146
2193
  }
@@ -2155,7 +2202,7 @@ class HandleImpl {
2155
2202
  * @experimental
2156
2203
  * @category handle & forking
2157
2204
  */
2158
- const fork = self => make(function (env, onResult) {
2205
+ const fork = self => make(function (env, onExit) {
2159
2206
  const signal = envGet(env, currentAbortSignal);
2160
2207
  const handle = new HandleImpl(signal);
2161
2208
  const nextEnv = envMutate(env, map => {
@@ -2164,11 +2211,11 @@ const fork = self => make(function (env, onResult) {
2164
2211
  return map;
2165
2212
  });
2166
2213
  yieldAdd(() => {
2167
- self[runSymbol](nextEnv, result => {
2168
- handle.emit(result);
2214
+ self[runSymbol](nextEnv, exit => {
2215
+ handle.emit(exit);
2169
2216
  });
2170
2217
  });
2171
- onResult(Either.right(handle));
2218
+ onExit(Either.right(handle));
2172
2219
  });
2173
2220
  /**
2174
2221
  * Run the `Micro` effect in a new `Handle` that can be awaited, joined, or
@@ -2181,7 +2228,7 @@ const fork = self => make(function (env, onResult) {
2181
2228
  * @category handle & forking
2182
2229
  */
2183
2230
  exports.fork = fork;
2184
- const forkDaemon = self => make(function (env, onResult) {
2231
+ const forkDaemon = self => make(function (env, onExit) {
2185
2232
  const controller = new AbortController();
2186
2233
  const handle = new HandleImpl(controller.signal, controller);
2187
2234
  const nextEnv = envMutate(env, map => {
@@ -2190,11 +2237,11 @@ const forkDaemon = self => make(function (env, onResult) {
2190
2237
  return map;
2191
2238
  });
2192
2239
  yieldAdd(() => {
2193
- self[runSymbol](nextEnv, result => {
2194
- handle.emit(result);
2240
+ self[runSymbol](nextEnv, exit => {
2241
+ handle.emit(exit);
2195
2242
  });
2196
2243
  });
2197
- onResult(Either.right(handle));
2244
+ onExit(Either.right(handle));
2198
2245
  });
2199
2246
  /**
2200
2247
  * Run the `Micro` effect in a new `Handle` that can be awaited, joined, or
@@ -2207,7 +2254,7 @@ const forkDaemon = self => make(function (env, onResult) {
2207
2254
  * @category handle & forking
2208
2255
  */
2209
2256
  exports.forkDaemon = forkDaemon;
2210
- const forkIn = exports.forkIn = /*#__PURE__*/(0, _Function.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))))));
2257
+ const forkIn = exports.forkIn = /*#__PURE__*/(0, _Function.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))))));
2211
2258
  /**
2212
2259
  * Run the `Micro` effect in a new `Handle` that can be awaited, joined, or
2213
2260
  * aborted.
@@ -2240,8 +2287,8 @@ const forkScoped = self => flatMap(scope, scope => forkIn(self, scope));
2240
2287
  * Micro.runFork
2241
2288
  * )
2242
2289
  *
2243
- * handle.addObserver((result) => {
2244
- * console.log(result)
2290
+ * handle.addObserver((exit) => {
2291
+ * console.log(exit)
2245
2292
  * })
2246
2293
  */
2247
2294
  exports.forkScoped = forkScoped;
@@ -2252,17 +2299,17 @@ const runFork = (effect, options) => {
2252
2299
  refs[currentAbortSignal.key] = controller.signal;
2253
2300
  const env = envMake(refs);
2254
2301
  const handle = new HandleImpl(controller.signal, controller);
2255
- effect[runSymbol](envSet(env, currentAbortSignal, handle._controller.signal), result => {
2256
- handle.emit(result);
2302
+ effect[runSymbol](envSet(env, currentAbortSignal, handle._controller.signal), exit => {
2303
+ handle.emit(exit);
2257
2304
  if (options?.signal) {
2258
- options.signal.removeEventListener("abort", handle.unsafeAbort);
2305
+ options.signal.removeEventListener("abort", handle.unsafeInterrupt);
2259
2306
  }
2260
2307
  });
2261
2308
  if (options?.signal) {
2262
2309
  if (options.signal.aborted) {
2263
- handle.unsafeAbort();
2310
+ handle.unsafeInterrupt();
2264
2311
  } else {
2265
- options.signal.addEventListener("abort", handle.unsafeAbort, {
2312
+ options.signal.addEventListener("abort", handle.unsafeInterrupt, {
2266
2313
  once: true
2267
2314
  });
2268
2315
  }
@@ -2271,14 +2318,14 @@ const runFork = (effect, options) => {
2271
2318
  };
2272
2319
  /**
2273
2320
  * Execute the `Micro` effect and return a `Promise` that resolves with the
2274
- * `Result` of the computation.
2321
+ * `MicroExit` of the computation.
2275
2322
  *
2276
- * @since 3.4.0
2323
+ * @since 3.4.6
2277
2324
  * @experimental
2278
2325
  * @category execution
2279
2326
  */
2280
2327
  exports.runFork = runFork;
2281
- const runPromiseResult = (effect, options) => new Promise((resolve, _reject) => {
2328
+ const runPromiseExit = (effect, options) => new Promise((resolve, _reject) => {
2282
2329
  const handle = runFork(effect, options);
2283
2330
  handle.addObserver(resolve);
2284
2331
  });
@@ -2290,34 +2337,34 @@ const runPromiseResult = (effect, options) => new Promise((resolve, _reject) =>
2290
2337
  * @experimental
2291
2338
  * @category execution
2292
2339
  */
2293
- exports.runPromiseResult = runPromiseResult;
2294
- const runPromise = (effect, options) => runPromiseResult(effect, options).then(result => {
2295
- if (result._tag === "Left") {
2296
- throw result.left;
2340
+ exports.runPromiseExit = runPromiseExit;
2341
+ const runPromise = (effect, options) => runPromiseExit(effect, options).then(exit => {
2342
+ if (exit._tag === "Left") {
2343
+ throw exit.left;
2297
2344
  }
2298
- return result.right;
2345
+ return exit.right;
2299
2346
  });
2300
2347
  /**
2301
- * Attempt to execute the `Micro` effect synchronously and return the `Result`.
2348
+ * Attempt to execute the `Micro` effect synchronously and return the `MicroExit`.
2302
2349
  *
2303
2350
  * If any asynchronous effects are encountered, the function will return a
2304
- * FailureUnexpected containing the `Handle`.
2351
+ * `CauseDie` containing the `Handle`.
2305
2352
  *
2306
- * @since 3.4.0
2353
+ * @since 3.4.6
2307
2354
  * @experimental
2308
2355
  * @category execution
2309
2356
  */
2310
2357
  exports.runPromise = runPromise;
2311
- const runSyncResult = effect => {
2358
+ const runSyncExit = effect => {
2312
2359
  const handle = runFork(effect);
2313
2360
  while (yieldState.tasks.length > 0) {
2314
2361
  yieldRunTasks();
2315
2362
  }
2316
- const result = handle.unsafePoll();
2317
- if (result === null) {
2318
- return ResultFailUnexpected(handle);
2363
+ const exit = handle.unsafePoll();
2364
+ if (exit === null) {
2365
+ return exitDie(handle);
2319
2366
  }
2320
- return result;
2367
+ return exit;
2321
2368
  };
2322
2369
  /**
2323
2370
  * Attempt to execute the `Micro` effect synchronously and return the success
@@ -2327,19 +2374,19 @@ const runSyncResult = effect => {
2327
2374
  * @experimental
2328
2375
  * @category execution
2329
2376
  */
2330
- exports.runSyncResult = runSyncResult;
2377
+ exports.runSyncExit = runSyncExit;
2331
2378
  const runSync = effect => {
2332
- const result = runSyncResult(effect);
2333
- if (result._tag === "Left") {
2334
- throw result.left;
2379
+ const exit = runSyncExit(effect);
2380
+ if (exit._tag === "Left") {
2381
+ throw exit.left;
2335
2382
  }
2336
- return result.right;
2383
+ return exit.right;
2337
2384
  };
2338
2385
  exports.runSync = runSync;
2339
2386
  const YieldableError = /*#__PURE__*/function () {
2340
2387
  class YieldableError extends globalThis.Error {
2341
- [runSymbol](_env, onResult) {
2342
- onResult(ResultFail(this));
2388
+ [runSymbol](_env, onExit) {
2389
+ onExit(exitFail(this));
2343
2390
  }
2344
2391
  toString() {
2345
2392
  return this.message ? `${this.name}: ${this.message}` : this.name;
@@ -2398,5 +2445,14 @@ const TaggedError = tag => {
2398
2445
  */
2399
2446
  exports.TaggedError = TaggedError;
2400
2447
  class NoSuchElementException extends TaggedError("NoSuchElementException") {}
2448
+ /**
2449
+ * Represents a checked exception which occurs when a timeout occurs.
2450
+ *
2451
+ * @since 3.4.4
2452
+ * @experimental
2453
+ * @category errors
2454
+ */
2401
2455
  exports.NoSuchElementException = NoSuchElementException;
2456
+ class TimeoutException extends TaggedError("TimeoutException") {}
2457
+ exports.TimeoutException = TimeoutException;
2402
2458
  //# sourceMappingURL=Micro.js.map