diff --git a/packages/effect-fc/src/Result.ts b/packages/effect-fc/src/Result.ts index f065082..4ddda52 100644 --- a/packages/effect-fc/src/Result.ts +++ b/packages/effect-fc/src/Result.ts @@ -29,7 +29,7 @@ export interface Initial extends Result.Prototype { export interface Running

extends Result.Prototype { readonly _tag: "Running" - readonly progress: P + readonly progress: Option.Option

} export interface Success extends Result.Prototype { @@ -45,7 +45,7 @@ export interface Failure extends Result.Prototype { export interface Refreshing

{ readonly refreshing: true - readonly progress: P + readonly progress: Option.Option

} @@ -96,7 +96,7 @@ const ResultPrototype = Object.freeze({ export interface ProgressService

{ - readonly update: (progress: P) => Effect.Effect + readonly update: (f: (previous: Option.Option

) => Option.Option

) => Effect.Effect } @@ -108,7 +108,10 @@ export const isFailure = (u: unknown): u is Failure => isResul export const isRefreshing = (u: unknown): u is Refreshing => isResult(u) && Predicate.hasProperty(u, "refreshing") && u.refreshing export const initial = (): Initial => Object.setPrototypeOf({ _tag: "Initial" }, ResultPrototype) -export const running =

(progress?: P): Running

=> Object.setPrototypeOf({ _tag: "Running", progress }, ResultPrototype) +export const running =

(progress?: P): Running

=> Object.setPrototypeOf({ + _tag: "Running", + progress: Option.fromNullable(progress), +}, ResultPrototype) export const succeed = (value: A): Success => Object.setPrototypeOf({ _tag: "Success", value }, ResultPrototype) export const fail = ( cause: Cause.Cause, @@ -122,7 +125,7 @@ export const refreshing = | Failure, P = never result: R, progress?: P, ): Omit>> & Refreshing

=> Object.setPrototypeOf( - Object.assign({}, result, { progress }), + Object.assign({}, result, { progress: Option.fromNullable(progress) }), Object.getPrototypeOf(result), ) @@ -146,9 +149,9 @@ export const toExit = ( } } -export const forkEffectScoped = ( - effect: Effect.Effect -): Effect.Effect>, never, Scope.Scope | R> => Queue.unbounded>().pipe( +export const forkEffectScoped = ( + effect: Effect.Effect | R> +): Effect.Effect>, never, Scope.Scope | R> => Queue.unbounded>().pipe( Effect.tap(Queue.offer(initial())), Effect.tap(queue => Effect.forkScoped(Effect.addFinalizer(() => Queue.shutdown(queue)).pipe( Effect.andThen(Queue.offer(queue, running())),