ErrorObserver work
Some checks failed
Lint / lint (push) Failing after 10s

This commit is contained in:
Julien Valverdé
2025-11-05 15:15:59 +01:00
parent 53bc4407b3
commit 5bc1e65a61

View File

@@ -1,15 +1,13 @@
import { type Cause, Context, Effect, Layer, type Queue, type Scope } from "effect" import { type Cause, Context, type Effect, Layer, type Queue, type Scope } from "effect"
export interface ErrorObserver<EIn, EOut> { export interface ErrorObserver<E = never> {
readonly "~In": EIn handle<Eff extends Effect.Effect<any, any, any>>(effect: Eff): Eff
readonly "~Out": EOut readonly subscribe: Effect.Effect<Queue.Dequeue<Cause.Cause<E>>, never, Scope.Scope>
readonly "~Caught": Exclude<EIn, EOut>
handle<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, Exclude<E, Exclude<EIn, EOut>>, R>
readonly subscribe: Effect.Effect<Queue.Dequeue<Cause.Cause<EIn>>, never, Scope.Scope>
} }
export const ErrorObserver = <E = never>(): Context.Tag<ErrorObserver<E>, ErrorObserver<E>> => Context.GenericTag("@effect-fc/ErrorObserver/ErrorObserver")
export namespace make { export namespace make {
export type Handler<EIn, EOut> = ( export type Handler<EIn, EOut> = (
@@ -24,34 +22,3 @@ export namespace make {
export const make = <EIn = never>() => <EOut>( export const make = <EIn = never>() => <EOut>(
f: make.Handler<NoInfer<EIn>, EOut> f: make.Handler<NoInfer<EIn>, EOut>
): Effect.Effect<ErrorObserver<EIn, EOut>> => ): Effect.Effect<ErrorObserver<EIn, EOut>> =>
export const ErrorObserver: Context.Tag<
ErrorObserver<unknown, unknown>,
ErrorObserver<unknown, unknown>
> = Context.GenericTag("@effect-fc/ErrorObserver/ErrorObserver")
export namespace Service {
export interface Result<Self, Id extends string, EIn, EOut>
extends Context.TagClass<Self, Id, ErrorObserver<EIn, EOut>> {
readonly Default: Layer.Layer<Self>
}
}
export const Service = <Self, EIn>() => (
<const Id extends string, EOut>(
id: Id,
f: (
self: Effect.Effect<never, NoInfer<EIn>>,
actions: {
failure(failure: NoInfer<EIn>): Effect.Effect<never>
defect(defect: unknown): Effect.Effect<never>
},
) => Effect.Effect<EOut>,
): Service.Result<Self, Id, EIn, EOut> => Layer.effect(
ErrorObserver as Context.Tag<ErrorObserver<EIn, EOut>, ErrorObserver<EIn, EOut>>,
Effect.gen(function*() {
},
))
)