# Fx.callback

Creates an Fx from a callback-based source.

## Signatures

```ts
export declare const callback: <A, E = never, R = never>(run: (emit: Emit<A, E>) => void | Effect.Effect<unknown, never, R>) => Fx<A, E, R>;
```

## Why

DOM events, sockets, observers, and foreign libraries decide when values exist.
`callback` turns that push boundary into `Fx` while keeping failure and cleanup
inside Effect's structured lifetime.

## Ownership and lifetime

Registration is lazy: `run` is called once for each `Fx` run. The run creates a
child scope and stays active until `emit.done()`, sink early exit, or interruption.
If `run` returns an Effect, it is registered as the scope finalizer. Each emit
operation starts its sink handler in a fiber, so handler completion can overlap;
use the returned fibers or a serialized source when ordering of effects matters.

## Examples

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

const messages = callback<string>((emit) => {
  const timer = setInterval(() => emit.succeed("tick"), 10)
  return Effect.sync(() => clearInterval(timer))
})
const program = collectUpTo(messages, 2)
```
