Hyperlinkv0.8.0-beta.28

Layer

Layer.suspendconsteffect/Layer.ts:1091
<A, E, R>(evaluate: LazyArg<Layer<A, E, R>>): Layer<A, E, R>

Constructs a layer lazily using the specified factory.

Details

The factory is evaluated only when the suspended layer is first built, and the result is memoized with normal layer sharing semantics.

Example (Choosing a layer lazily)

import { Context, Layer } from "effect"

class Config extends Context.Service<Config, string>()("Config") {}

const useProd = true

const layer = Layer.suspend(() =>
  useProd
    ? Layer.succeed(Config, "https://api.example.com")
    : Layer.succeed(Config, "http://localhost:3000")
)
constructors
Source effect/Layer.ts:10912 lines
export const suspend = <A, E, R>(evaluate: LazyArg<Layer<A, E, R>>): Layer<A, E, R> =>
  fromBuildMemo((memoMap, scope) => internalEffect.suspend(() => evaluate().build(memoMap, scope)))