# AsyncData

The complete renderer-independent state machine for asynchronous data.

## Signatures

```ts
export type AsyncData<A, E> = NoData | Loading | Success<A> | Failure<E> | Optimistic<A, E>;
```

```ts
export declare const AsyncData: <const A extends Schema.Top, E extends Schema.Top>(A: A, E: E) => Schema.Codec<AsyncData<A["Type"], E["Type"]>, EncodedAsyncData<A["Encoded"], E["Encoded"]>, A["DecodingServices"] | E["DecodingServices"], A["EncodingServices"] | E["EncodingServices"]>;
```

## Why

A closed union makes absence, work, value, failure, and optimistic history compositional and exhaustively matchable.

## Ownership and lifetime

AsyncData values acquire no resources; they describe operation state whose execution is owned elsewhere.

## Examples

```ts
import type { AsyncData } from "@typed/async-data"
import { success } from "@typed/async-data"
const state: AsyncData<number, string> = success(1)
```

```ts
import { AsyncData } from "@typed/async-data"
import { Schema } from "effect"
const codec = AsyncData(Schema.String, Schema.String)
```
See [Effect Schema](https://effect.website/docs/schema/introduction/).
