0.2.5 #43
@@ -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")
|
export const ResultTypeId: unique symbol = Symbol.for("@effect-fc/Result/Result")
|
||||||
@@ -215,17 +215,17 @@ export namespace unsafeForkEffect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const unsafeForkEffect = <A, E, R, P = never>(
|
export const unsafeForkEffect = Effect.fnUntraced(function* <A, E, R, P = never>(
|
||||||
effect: Effect.Effect<A, E, R>,
|
effect: Effect.Effect<A, E, R>,
|
||||||
options?: unsafeForkEffect.Options<NoInfer<A>, NoInfer<E>, P>,
|
options?: unsafeForkEffect.Options<NoInfer<A>, NoInfer<E>, P>,
|
||||||
): Effect.Effect<
|
): Effect.fn.Return<
|
||||||
readonly [result: Subscribable.Subscribable<Result<A, E, P>, never, never>, fiber: Fiber.Fiber<A, E>],
|
readonly [result: Subscribable.Subscribable<Result<A, E, P>, never, never>, fiber: Fiber.Fiber<A, E>],
|
||||||
never,
|
never,
|
||||||
Scope.Scope | unsafeForkEffect.OutputContext<A, E, R, P>
|
Scope.Scope | unsafeForkEffect.OutputContext<A, E, R, P>
|
||||||
> => Effect.Do.pipe(
|
> {
|
||||||
Effect.bind("ref", () => Ref.make(options?.initial ?? initial<A, E, P>())),
|
const ref = yield* Ref.make(options?.initial ?? initial<A, E, P>())
|
||||||
Effect.bind("pubsub", () => PubSub.unbounded<Result<A, E, P>>()),
|
const pubsub = yield* PubSub.unbounded<Result<A, E, P>>()
|
||||||
Effect.bind("fiber", ({ ref, pubsub }) => Effect.forkScoped(State<A, E, P>().pipe(
|
const fiber = yield* (Effect.forkScoped(State<A, E, P>().pipe(
|
||||||
Effect.andThen(state => state.set(
|
Effect.andThen(state => state.set(
|
||||||
(isFinal(options?.initial) && hasWillRefreshFlag(options?.initial))
|
(isFinal(options?.initial) && hasWillRefreshFlag(options?.initial))
|
||||||
? refreshing(options.initial, options?.initialProgress) as Result<A, E, P>
|
? refreshing(options.initial, options?.initialProgress) as Result<A, E, P>
|
||||||
@@ -244,8 +244,9 @@ export const unsafeForkEffect = <A, E, R, P = never>(
|
|||||||
set: v => Effect.andThen(Ref.set(ref, v), PubSub.publish(pubsub, v))
|
set: v => Effect.andThen(Ref.set(ref, v), PubSub.publish(pubsub, v))
|
||||||
})),
|
})),
|
||||||
)),
|
)),
|
||||||
))),
|
)) as Effect.Effect<Fiber.Fiber<A, E>, never, Scope.Scope | unsafeForkEffect.OutputContext<A, E, R, P>>)
|
||||||
Effect.map(({ ref, pubsub, fiber }) => [
|
|
||||||
|
return [
|
||||||
Subscribable.make({
|
Subscribable.make({
|
||||||
get: Ref.get(ref),
|
get: Ref.get(ref),
|
||||||
changes: Stream.unwrapScoped(Effect.map(
|
changes: Stream.unwrapScoped(Effect.map(
|
||||||
@@ -254,12 +255,8 @@ export const unsafeForkEffect = <A, E, R, P = never>(
|
|||||||
)),
|
)),
|
||||||
}),
|
}),
|
||||||
fiber,
|
fiber,
|
||||||
]),
|
] as const
|
||||||
) as Effect.Effect<
|
})
|
||||||
readonly [result: Subscribable.Subscribable<Result<A, E, P>, never, never>, fiber: Fiber.Fiber<A, E>],
|
|
||||||
never,
|
|
||||||
Scope.Scope | unsafeForkEffect.OutputContext<A, E, R, P>
|
|
||||||
>
|
|
||||||
|
|
||||||
export namespace forkEffect {
|
export namespace forkEffect {
|
||||||
export type InputContext<R, P> = R extends Progress<infer X> ? [X] extends [P] ? R : never : R
|
export type InputContext<R, P> = R extends Progress<infer X> ? [X] extends [P] ? R : never : R
|
||||||
|
|||||||
Reference in New Issue
Block a user