=> isResult(u) && u._tag === "Failure"
+export const isFailure = (u: unknown): u is Failure => isResult(u) && u._tag === "Failure"
export const hasFlag = (u: unknown): u is Flags => isResult(u) && Predicate.hasProperty(u, "_flag")
export const hasWillFetchFlag = (u: unknown): u is WillFetch => isResult(u) && Predicate.hasProperty(u, "_flag") && u._flag === "WillFetch"
export const hasWillRefreshFlag = (u: unknown): u is WillRefresh => isResult(u) && Predicate.hasProperty(u, "_flag") && u._flag === "WillRefresh"
@@ -117,15 +116,7 @@ export const initial: {
} = (): Initial => Object.setPrototypeOf({ _tag: "Initial" }, ResultPrototype)
export const running = (progress?: P): Running
=> Object.setPrototypeOf({ _tag: "Running", progress }, ResultPrototype)
export const succeed = (value: A): Success => Object.setPrototypeOf({ _tag: "Success", value }, ResultPrototype)
-
-export const fail = (
- cause: Cause.Cause,
- previousSuccess?: Success>,
-): Failure => Object.setPrototypeOf({
- _tag: "Failure",
- cause,
- previousSuccess: Option.fromNullable(previousSuccess),
-}, ResultPrototype)
+export const fail = (cause: Cause.Cause ): Failure => Object.setPrototypeOf({ _tag: "Failure", cause }, ResultPrototype)
export const willFetch = >(
result: R
@@ -150,11 +141,8 @@ export const refreshing = , P = never>(
)
export const fromExit = (
- exit: Exit.Exit,
- previousSuccess?: Success>,
-): Success | Failure => exit._tag === "Success"
- ? succeed(exit.value)
- : fail(exit.cause, previousSuccess)
+ exit: Exit.Exit
+): Success | Failure => exit._tag === "Success" ? succeed(exit.value) : fail(exit.cause)
export const toExit = (
self: Result
@@ -219,7 +207,7 @@ export namespace unsafeForkEffect {
export interface Options {
// biome-ignore lint/complexity/noBannedTypes: "{}" is relevant here
- readonly initial?: (Initial | Success | Failure) & ({} | WillFetch | WillRefresh)
+ readonly initial?: (Initial | Success | Failure) & ({} | WillFetch | WillRefresh)
readonly initialProgress?: P
}
}
@@ -242,10 +230,7 @@ export const unsafeForkEffect = (
).pipe(
Effect.andThen(effect),
Effect.onExit(exit => Effect.andThen(
- state.set(fromExit(
- exit,
- isSuccess(options?.initial) ? options.initial : undefined),
- ),
+ state.set(fromExit(exit)),
Effect.forkScoped(PubSub.shutdown(pubsub)),
)),
)),