From aa243c6493492f73b84f5c1fbac971ebd3b0c1a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 24 Nov 2025 02:30:29 +0100 Subject: [PATCH] Fix --- packages/effect-fc/src/Query.ts | 6 ++++-- packages/effect-fc/src/Result.ts | 33 ++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/packages/effect-fc/src/Query.ts b/packages/effect-fc/src/Query.ts index 4429b31..3c7a2f5 100644 --- a/packages/effect-fc/src/Query.ts +++ b/packages/effect-fc/src/Query.ts @@ -41,7 +41,9 @@ extends Pipeable.Class() implements Query { })) } - start(key: K): Effect.Effect< + start( + key: K + ): Effect.Effect< Subscribable.Subscribable>, never, Scope.Scope | R @@ -61,7 +63,7 @@ extends Pipeable.Class() implements Query { return Effect.andThen( sub.get, initial => Stream.runFoldEffect( - sub.changes, + Stream.filter(sub.changes, Predicate.not(Result.isInitial)), initial, (_, result) => Effect.as(SubscriptionRef.set(this.result, result), result), ), diff --git a/packages/effect-fc/src/Result.ts b/packages/effect-fc/src/Result.ts index 16c7815..ec2679f 100644 --- a/packages/effect-fc/src/Result.ts +++ b/packages/effect-fc/src/Result.ts @@ -111,7 +111,7 @@ export const succeed = (value: A): Success => Object.setPrototypeOf({ _tag export const fail = ( cause: Cause.Cause, - previousSuccess?: Success, + previousSuccess?: Success>, ): Failure => Object.setPrototypeOf({ _tag: "Failure", cause, @@ -126,10 +126,11 @@ export const refreshing = | Failure, P = never ) export const fromExit = ( - exit: Exit.Exit + exit: Exit.Exit, + previousSuccess?: Success>, ): Success | Failure => exit._tag === "Success" ? succeed(exit.value) - : fail(exit.cause) + : fail(exit.cause, previousSuccess) export const toExit = ( self: Result @@ -192,14 +193,23 @@ export const makeProgressLayer = (): Layer.Layer< export namespace unsafeForkEffect { export type OutputContext = Exclude | Progress

| Progress> - export interface Options

{ + export type Options = { readonly initialProgress?: P - } + readonly previous?: Success | Failure + } & ( + | { + readonly refreshing: true + readonly previous: Success | Failure + } + | { + readonly refreshing?: false + } + ) } export const unsafeForkEffect = ( effect: Effect.Effect, - options?: unsafeForkEffect.Options

, + options?: unsafeForkEffect.Options, NoInfer, P>, ): Effect.Effect< readonly [result: Subscribable.Subscribable, never, never>, fiber: Fiber.Fiber], never, @@ -208,10 +218,13 @@ export const unsafeForkEffect = ( Effect.bind("ref", () => Ref.make(initial())), Effect.bind("pubsub", () => PubSub.unbounded>()), Effect.bind("fiber", ({ ref, pubsub }) => Effect.forkScoped(State().pipe( - Effect.andThen(state => state.set(running(options?.initialProgress)).pipe( + Effect.andThen(state => state.set(options?.refreshing + ? refreshing(options.previous, options?.initialProgress) as Result + : running(options?.initialProgress) + ).pipe( Effect.andThen(effect), Effect.onExit(exit => Effect.andThen( - state.set(fromExit(exit)), + state.set(fromExit(exit, (options?.previous && isSuccess(options.previous)) ? options.previous : undefined)), Effect.forkScoped(PubSub.shutdown(pubsub)), )), )), @@ -242,13 +255,13 @@ export const unsafeForkEffect = ( export namespace forkEffect { export type InputContext = R extends Progress ? [X] extends [P] ? R : never : R export type OutputContext = unsafeForkEffect.OutputContext - export interface Options

extends unsafeForkEffect.Options

{} + export type Options = unsafeForkEffect.Options } export const forkEffect: { ( effect: Effect.Effect>>, - options?: forkEffect.Options

, + options?: forkEffect.Options, NoInfer, P>, ): Effect.Effect< readonly [result: Subscribable.Subscribable, never, never>, fiber: Fiber.Fiber], never,