# Fx.drainLayer

Runs an `Fx` stream as a Layer.
The stream is forked in the background when the layer is acquired.

## Signatures

```ts
export declare const drainLayer: <A, E, R>(fx: Fx<A, E, R>) => Layer<never, E, Exclude<R, Scope>>;
```

## Why

A background producer can share the same acquisition and shutdown boundary as an
application's Effect [Layer](https://effect.website/docs/v4/api/effect/Layer) graph
even when it provides no service itself.

## Ownership and lifetime

Building the Layer starts `drain(fx)` with `forkScoped`. Acquisition succeeds after
the fiber is registered; it does not wait for that fiber. The Layer scope interrupts
the fiber on release. A source failure is stored in the discarded child Fiber exit:
it does not fail Layer acquisition and this API exposes no handle for awaiting it.
Recover, report, or otherwise observe failures inside `fx` before calling
`drainLayer`, or use `fork` when the caller needs the Fiber exit. The annotated `E`
channel remains in the public Layer type even though the background exit is not
propagated by this implementation. `Scope` is supplied by the Layer.

## Examples

```ts
import { Effect } from "effect"
import { Fx } from "@typed/fx"

const reported = Fx.fail("offline").pipe(
  Fx.catch((error) => Fx.fromEffect(Effect.logError(error)))
)
const Background = Fx.drainLayer(reported)
const program = Effect.void.pipe(Effect.provide(Background))
```
