effect-io-ai

Package: effect
Module: Layer

Layer.syncContext

Constructs a layer lazily that provides all services in a Context.

When to use

Use when you need a Layer that creates multiple services synchronously but defers that work until the layer is built.

Details

This is a lazy version of succeedContext where the Context is computed synchronously only when the layer is built.

Example (Lazily providing a context)

import { Context, Effect, Layer } from "effect"

class Database extends Context.Service<Database, {
  readonly query: (sql: string) => Effect.Effect<string>
}>()("Database") {}

const layer = Layer.syncContext(() =>
  Context.make(Database, {
    query: (sql: string) => Effect.succeed(`Query: ${sql}`)
  })
)

See

Signature

declare const syncContext: <A>(evaluate: LazyArg<Context.Context<A>>) => Layer<A>

Source

Since v2.0.0