This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
import { Effect, Function, Predicate, Runtime, Scope } from "effect"
|
import { Effect, Function, Predicate, Runtime, Scope } from "effect"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import * as Component from "./Component.js"
|
import * as Component from "./Component.js"
|
||||||
import * as ErrorObserver from "./ErrorObserver.js"
|
|
||||||
|
|
||||||
|
|
||||||
export const TypeId: unique symbol = Symbol.for("@effect-fc/Async/Async")
|
export const TypeId: unique symbol = Symbol.for("@effect-fc/Async/Async")
|
||||||
@@ -32,10 +31,10 @@ const SuspenseProto = Object.freeze({
|
|||||||
|
|
||||||
return ({ fallback, name, ...props }: Async.Props) => {
|
return ({ fallback, name, ...props }: Async.Props) => {
|
||||||
const promise = Runtime.runPromise(runtimeRef.current)(
|
const promise = Runtime.runPromise(runtimeRef.current)(
|
||||||
ErrorObserver.handle(Effect.andThen(
|
Effect.andThen(
|
||||||
Component.useScope([], this),
|
Component.useScope([], this),
|
||||||
scope => Effect.provideService(this.body(props as P), Scope.Scope, scope),
|
scope => Effect.provideService(this.body(props as P), Scope.Scope, scope),
|
||||||
))
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return React.createElement(
|
return React.createElement(
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
/** biome-ignore-all lint/complexity/useArrowFunction: necessary for class prototypes */
|
/** biome-ignore-all lint/complexity/useArrowFunction: necessary for class prototypes */
|
||||||
import { Context, type Duration, Effect, Effectable, Equivalence, ExecutionStrategy, Exit, Fiber, Function, HashMap, Layer, ManagedRuntime, Option, Predicate, Ref, Runtime, Scope, Tracer, type Utils } from "effect"
|
import { Context, type Duration, Effect, Effectable, Equivalence, ExecutionStrategy, Exit, Fiber, Function, HashMap, Layer, ManagedRuntime, Option, Predicate, Ref, Runtime, Scope, Tracer, type Utils } from "effect"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import * as ErrorObserver from "./ErrorObserver.js"
|
|
||||||
import { Memoized } from "./index.js"
|
import { Memoized } from "./index.js"
|
||||||
|
|
||||||
|
|
||||||
@@ -76,10 +75,10 @@ const ComponentProto = Object.freeze({
|
|||||||
runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>,
|
runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>,
|
||||||
) {
|
) {
|
||||||
return (props: P) => Runtime.runSync(runtimeRef.current)(
|
return (props: P) => Runtime.runSync(runtimeRef.current)(
|
||||||
ErrorObserver.handle(Effect.andThen(
|
Effect.andThen(
|
||||||
useScope([], this),
|
useScope([], this),
|
||||||
scope => Effect.provideService(this.body(props), Scope.Scope, scope),
|
scope => Effect.provideService(this.body(props), Scope.Scope, scope),
|
||||||
))
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
} as const)
|
} as const)
|
||||||
@@ -548,15 +547,14 @@ const runReactEffect = <E, R>(
|
|||||||
() => {
|
() => {
|
||||||
switch (options?.finalizerExecutionMode ?? "fork") {
|
switch (options?.finalizerExecutionMode ?? "fork") {
|
||||||
case "sync":
|
case "sync":
|
||||||
Runtime.runSync(runtime)(ErrorObserver.handle(Scope.close(scope, Exit.void)))
|
Runtime.runSync(runtime)(Scope.close(scope, Exit.void))
|
||||||
break
|
break
|
||||||
case "fork":
|
case "fork":
|
||||||
Runtime.runFork(runtime)(ErrorObserver.handle(Scope.close(scope, Exit.void)))
|
Runtime.runFork(runtime)(Scope.close(scope, Exit.void))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
ErrorObserver.handle,
|
|
||||||
Runtime.runSync(runtime),
|
Runtime.runSync(runtime),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { type Cause, Context, Effect, Layer, Option, Pipeable, Predicate, PubSub, type Queue, type Scope } from "effect"
|
import { type Cause, Context, Effect, Exit, Layer, Option, Pipeable, Predicate, PubSub, type Queue, type Scope, Supervisor } from "effect"
|
||||||
|
|
||||||
|
|
||||||
export const TypeId: unique symbol = Symbol.for("@effect-fc/ErrorObserver/ErrorObserver")
|
export const TypeId: unique symbol = Symbol.for("@effect-fc/ErrorObserver/ErrorObserver")
|
||||||
@@ -29,12 +29,27 @@ extends Pipeable.Class() implements ErrorObserver<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ErrorObserverSupervisorImpl extends Supervisor.AbstractSupervisor<void> {
|
||||||
|
readonly value = Effect.void
|
||||||
|
constructor(readonly pubsub: PubSub.PubSub<Cause.Cause<never>>) {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
|
||||||
|
onEnd<A, E>(_value: Exit.Exit<A, E>): void {
|
||||||
|
if (Exit.isFailure(_value))
|
||||||
|
Effect.runSync(PubSub.publish(this.pubsub, _value.cause as Cause.Cause<never>))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const isErrorObserver = (u: unknown): u is ErrorObserver<unknown> => Predicate.hasProperty(u, TypeId)
|
export const isErrorObserver = (u: unknown): u is ErrorObserver<unknown> => Predicate.hasProperty(u, TypeId)
|
||||||
|
|
||||||
export const layer: Layer.Layer<ErrorObserver> = Layer.effect(ErrorObserver(), Effect.andThen(
|
export const layer: Layer.Layer<ErrorObserver> = Layer.unwrapEffect(Effect.map(
|
||||||
PubSub.unbounded<Cause.Cause<never>>(),
|
PubSub.unbounded<Cause.Cause<never>>(),
|
||||||
pubsub => new ErrorObserverImpl(pubsub),
|
pubsub => Layer.merge(
|
||||||
|
Supervisor.addSupervisor(new ErrorObserverSupervisorImpl(pubsub)),
|
||||||
|
Layer.succeed(ErrorObserver(), new ErrorObserverImpl(pubsub)),
|
||||||
|
),
|
||||||
))
|
))
|
||||||
|
|
||||||
export const handle = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => Effect.andThen(
|
export const handle = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => Effect.andThen(
|
||||||
|
|||||||
Reference in New Issue
Block a user