# Subject.share

Shares one active execution of an `Fx` among subscribers through the supplied `Subject`.

## Signatures

```ts
export declare function share<A, E, R, R2>(fx: Fx.Fx<A, E, R>, subject: Subject<A, E, R2>): Fx.Fx<A, E, R | R2 | Scope.Scope>;
```

## Why

Use `share` when the caller must choose the multicast boundary—for example, a replaying subject,
a renderer-independent state object, or a service-backed subject—while ensuring that simultaneous
consumers do not duplicate the source's effects.

## Subscription and publication

A subscriber is registered with the subject before the source starts, so the first subscriber
observes synchronous first values and failures. The first active subscriber starts the source;
later subscribers join that execution. When the last subscriber leaves, the source fiber is
interrupted. A later subscriber starts a fresh session.

## Errors, services, and interruption

Source successes and failures are pushed unchanged through the subject. The returned `Fx`
requires the union of source services and subject services.

## Ownership and lifetime

`Scope` owns each individual subscription. The shared source is finalized exactly once when the
active session ends or the source itself exits. `share` takes session ownership of the supplied
subject: source exit calls its `interrupt`, closing all of that subject's subscribers and clearing
retained state. Do not concurrently reuse the same subject for an independently owned producer
or subscriber population.

## Examples

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

const backing = Subject.unsafeMake<number>(1)
const request = Fx.fromEffect(Effect.succeed(42))
const shared = Subject.share(request, backing)
```
