IFClite TypeScript API
    Preparing search index...

    Type Alias LifetimeState<T>

    LifetimeState:
        | { generation: number; kind: "idle" }
        | { generation: number; kind: "initializing"; promise: Promise<T> }
        | { generation: number; kind: "ready"; value: T }
        | { error: unknown; generation: number; kind: "failed" }
        | { generation: number; kind: "disposed" }

    Single-flight, generation-checked init for a long-lived resource (an engine handle, a native bridge, a wasm module).

    A boolean plus a cached promise cannot tell "in flight" from "not started", nor notice a dispose() that landed mid-init: overlapping init() calls each built a resource (the first leaked), init resumed after dispose() to resurrect it, and a stale attempt's failure cleared the promise of the attempt that replaced it. The contract here:

    • Concurrent init() calls join one in-flight attempt; once ready, init resolves with the cached value.
    • A failed attempt is forgotten (failed), so the next init() retries.
    • dispose() bumps the generation and releases a ready value. An attempt started under an older generation is stale: its success rejects as superseded (its value is released, never cached) and its failure touches nothing. start can poll attempt.isCurrent() to skip building at all.
    • Dispose is not terminal: the next init() builds afresh.

    Type Parameters

    • T