type-alias / @typed/async-data

AsyncData

The complete renderer-independent state machine for asynchronous data.

Package version
1.0.0-beta.7
Category
State models
Since
1.0.0

Import

import { AsyncData } from "@typed/async-data";

Signatures

export type AsyncData<A, E> = NoData | Loading | Success<A> | Failure<E> | Optimistic<A, E>;
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

import type { AsyncData } from "@typed/async-data"
import { success } from "@typed/async-data"
const state: AsyncData<number, string> = success(1)
import { AsyncData } from "@typed/async-data"
import { Schema } from "effect"
const codec = AsyncData(Schema.String, Schema.String)

See Effect Schema.

Source