diff --git a/packages/effect-fc/src/Result.ts b/packages/effect-fc/src/Result.ts index ad2cf69..70ecbe7 100644 --- a/packages/effect-fc/src/Result.ts +++ b/packages/effect-fc/src/Result.ts @@ -1,4 +1,4 @@ -import { Cause, Context, Data, Effect, Equal, Exit, type Fiber, Hash, Layer, Match, Pipeable, Predicate, PubSub, pipe, Ref, type Scope, Stream, Subscribable } from "effect" +import { Cause, Context, Data, Effect, Equal, Exit, type Fiber, Hash, Layer, Match, pipe, Pipeable, Predicate, PubSub, Ref, type Scope, Stream, Subscribable } from "effect" export const ResultTypeId: unique symbol = Symbol.for("@effect-fc/Result/Result") @@ -215,17 +215,17 @@ export namespace unsafeForkEffect { } } -export const unsafeForkEffect = ( +export const unsafeForkEffect = Effect.fnUntraced(function* ( effect: Effect.Effect, options?: unsafeForkEffect.Options, NoInfer, P>, -): Effect.Effect< +): Effect.fn.Return< readonly [result: Subscribable.Subscribable, never, never>, fiber: Fiber.Fiber], never, Scope.Scope | unsafeForkEffect.OutputContext -> => Effect.Do.pipe( - Effect.bind("ref", () => Ref.make(options?.initial ?? initial())), - Effect.bind("pubsub", () => PubSub.unbounded>()), - Effect.bind("fiber", ({ ref, pubsub }) => Effect.forkScoped(State().pipe( +> { + const ref = yield* Ref.make(options?.initial ?? initial()) + const pubsub = yield* PubSub.unbounded>() + const fiber = yield* (Effect.forkScoped(State().pipe( Effect.andThen(state => state.set( (isFinal(options?.initial) && hasWillRefreshFlag(options?.initial)) ? refreshing(options.initial, options?.initialProgress) as Result @@ -244,8 +244,9 @@ export const unsafeForkEffect = ( set: v => Effect.andThen(Ref.set(ref, v), PubSub.publish(pubsub, v)) })), )), - ))), - Effect.map(({ ref, pubsub, fiber }) => [ + )) as Effect.Effect, never, Scope.Scope | unsafeForkEffect.OutputContext>) + + return [ Subscribable.make({ get: Ref.get(ref), changes: Stream.unwrapScoped(Effect.map( @@ -254,12 +255,8 @@ export const unsafeForkEffect = ( )), }), fiber, - ]), -) as Effect.Effect< - readonly [result: Subscribable.Subscribable, never, never>, fiber: Fiber.Fiber], - never, - Scope.Scope | unsafeForkEffect.OutputContext -> + ] as const +}) export namespace forkEffect { export type InputContext = R extends Progress ? [X] extends [P] ? R : never : R