# provide

Builds a Layer for each subscription and provides it to the entire Fx run.

## Signatures

```ts
export declare const provide: {
    <R2, E2 = never, R3 = never>(layer: Layer.Layer<R2, E2, R3>): <A, E, R>(fx: Fx<A, E, R>) => Fx<A, E | E2, Exclude<R, R2> | R3>;
    <A, E, R, R2, E2 = never, R3 = never>(fx: Fx<A, E, R>, layer: Layer.Layer<R2, E2, R3>): Fx<A, E | E2, Exclude<R, R2> | R3>;
};
```

## Why

Fx preserves Effect service requirements in `R`; providing a Layer closes
those requirements while retaining acquisition failures and dependencies in
the resulting type.

## Ownership and lifetime

Each subscription creates a private Scope and builds the Layer inside it
before the source starts. A build failure is sent to the sink and the source
never runs. Otherwise the built Context is available to every source Effect,
and the Scope closes with the source's success, failure, defect, or
interruption. Provided services are removed from `R`; Layer dependencies and
errors are added.

## Examples

```ts
import { Context, Effect, Layer } from "effect"
import { provide } from "@typed/fx/Fx"
import { fromEffect } from "@typed/fx/Fx"

class Config extends Context.Service<Config, { readonly url: string }>()("Config") {}
const request = fromEffect(Effect.map(Config, ({ url }) => url))
const runnable = provide(request, Layer.succeed(Config, { url: "/api" }))
```
