(options?: {
readonly path?: string
readonly unlink?: boolean
}): Layer.Layer<Services>Bind-or-dial a same-machine Lookup path (L1 / D7).
First process serves Identity+Directory+Advice; later processes dial
(Layer.catchCause). Default unlink: false so a second process cannot unlink-steal
a live sock (stale socks: pass unlink: true or a fresh path).
Effect precedent: layerAgentOptions — pair with layer for the zero-config value.
export const const layerOptions: (options?: {
readonly path?: string
readonly unlink?: boolean
}) => Layer.Layer<Services>
Bind-or-dial a same-machine Lookup path (L1 / D7).
First process serves
Identity
+
Directory
+
Advice
; later processes dial
(Layer.catchCause). Default unlink: false so a second process cannot unlink-steal
a live sock (stale socks: pass unlink: true or a fresh path).
Effect precedent: layerAgentOptions — pair with
layer
for the zero-config value.
layerOptions = (options: | {
readonly path?: string
readonly unlink?: boolean
}
| undefined
options?: {
readonly path?: string | undefinedpath?: string;
readonly unlink?: boolean | undefinedunlink?: boolean;
}): import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<type Services =
| Identity
| Directory
| Advice
Services a Lookup client layer provides — identity, directory, and placement advice.
Services> => {
const const path: stringpath = options: | {
readonly path?: string
readonly unlink?: boolean
}
| undefined
options?.path?: string | undefinedpath ?? const defaultIpcPath: "/tmp/hyperlink-ts-lookup.sock"Well-known Unix socket path for same-machine default lookup (L1).
Prefer overriding in tests so suites don't collide on one machine.
defaultIpcPath;
return const layerIpc: (
path: string,
options?: {
readonly unlink?: boolean
readonly onConflict?: OnConflictResolved
}
) => any
layerIpc(const path: stringpath, {
unlink?: boolean | undefinedunlink: options: | {
readonly path?: string
readonly unlink?: boolean
}
| undefined
options?.unlink?: boolean | undefinedunlink ?? false,
}).pipe(
import LayerLayer.const catchCause: <unknown, never, LookupUnaddressed, Services>(onError: (cause: Cause<unknown>) => Layer.Layer<Services, LookupUnaddressed, never>) => <RIn, ROut>(self: Layer.Layer<ROut, unknown, RIn>) => Layer.Layer<ROut & Services, LookupUnaddressed, RIn> (+1 overload)Recovers from any failure cause by switching to another layer.
When to use
Use when you need Layer recovery to inspect more than the typed error,
such as defects or interruption information.
Details
The handler receives the full Cause of the failed layer, including typed
errors, unexpected defects, and interruption information, and returns the
fallback layer to build instead. Finalizers for resources acquired by the
failed layer are still run before the fallback layer is acquired.
Example (Recovering from layer failures by cause)
import { Context, Data, Effect, Layer } from "effect"
class DatabaseError extends Data.TaggedError("DatabaseError")<{
message: string
}> {}
class Database extends Context.Service<Database, {
readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}
const primaryDatabaseLayer = Layer.effect(Database,
Effect.fail(new DatabaseError({ message: "Primary DB unreachable" }))
)
const databaseWithFallback = primaryDatabaseLayer.pipe(
Layer.catchCause(() => {
return Layer.succeed(Database, {
query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Memory: ${sql}`))
})
})
)
const program = Effect.gen(function*() {
const database = yield* Database
const result = yield* database.query("SELECT * FROM users")
console.log(result)
}).pipe(
Effect.provide(databaseWithFallback)
)
Effect.runPromise(program)
// Memory: SELECT * FROM users
catchCause(() => const clientOptions: (options?: {
readonly path?: string
}) => Layer.Layer<Services, LookupUnaddressed>
Dial the same-machine Lookup path (
defaultIpcPath
or options.path).
Effect precedent: options factory beside a default Layer value (layerAgentOptions).
clientOptions({ path?: string | undefinedpath })),
) as import LayerLayer.interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<type Services =
| Identity
| Directory
| Advice
Services a Lookup client layer provides — identity, directory, and placement advice.
Services>;
};