interface / @typed/async-data

Success

Represents a successfully produced value, optionally while it refreshes.

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

Import

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

Signatures

export interface Success<A> {
    readonly _tag: "Success";
    readonly value: A;
    readonly progress?: Progress | undefined;
}

Why

Success keeps the last usable value available while progress can describe newer work.

Ownership and lifetime

This plain wrapper acquires no resources; ownership of value remains with the caller and readonly does not freeze either object.

Property: _tag

The discriminant for a successful value.

Property: _tag: Why

The literal tag enables exhaustive success handling without inspecting the payload.

Property: _tag: Ownership and lifetime

Inherits the resource-free lifetime of its enclosing state.

Property: progress

Optional progress for a refresh of the successful value.

Property: progress: Why

Its presence distinguishes refreshing success from a settled success.

Property: progress: Ownership and lifetime

Inherits the resource-free lifetime of its enclosing state.

Property: value

The most recently successful value.

Property: value: Why

The payload remains directly accessible even when progress marks a refresh.

Property: value: Ownership and lifetime

Inherits the enclosing state’s lifetime; the caller retains ownership of the referenced value.

Examples

import { success } from "@typed/async-data"
const state = success({ id: 1 })

Source