Logos DX
    Preparing search index...

    Interface InflightOptions<Args, Key, Value>

    Configuration options for in-flight promise deduplication.

    interface InflightOptions<
        Args extends any[] = any[],
        Key = string,
        Value = unknown,
    > {
        generateKey?: (...args: Args) => Key;
        onJoin?: (key: Key) => void;
        onReject?: (key: Key, error: unknown) => void;
        onResolve?: (key: Key, value: Value) => void;
        onStart?: (key: Key) => void;
        shouldDedupe?: (...args: Args) => boolean;
    }

    Type Parameters

    • Args extends any[] = any[]
    • Key = string
    • Value = unknown
    Index

    Properties

    generateKey?: (...args: Args) => Key

    Optional key generation function. If omitted, uses a built-in serializer that handles:

    • Primitives (string, number, boolean, null, undefined, bigint)
    • Objects (plain objects with sorted keys for consistency)
    • Arrays (preserves order)
    • Dates (serialized as timestamps)
    • RegExp (serialized as source/flags)
    • Maps and Sets (serialized with sorted entries)
    • Circular references (detected and marked)

    Unsupported types (serialized but may cause collisions):

    • Functions: Serialized as "[Function]" - all functions collide
    • Symbols: Serialized by description - symbols with same description collide
    • WeakMap/WeakSet: Serialized as "[WeakMap/WeakSet]" - all instances collide
    • Errors: Serialized by name and message only

    For identity-based deduplication, functions as arguments, or performance-critical hot paths, provide a custom generateKey that extracts only discriminating fields (e.g., (id, _opts) => id).

    onJoin?: (key: Key) => void

    Called when subsequent caller joins existing in-flight promise. Must be synchronous. Errors are silently caught.

    onReject?: (key: Key, error: unknown) => void

    Called when shared promise rejects. Must be synchronous. Errors are silently caught.

    onResolve?: (key: Key, value: Value) => void

    Called when shared promise resolves successfully. Must be synchronous. Errors are silently caught.

    onStart?: (key: Key) => void

    Called when first caller starts producer for this key (before producer executes). Must be synchronous. Errors are silently caught.

    shouldDedupe?: (...args: Args) => boolean

    Pre-serialization check. Return false to bypass deduplication and execute the producer directly.

    This is called BEFORE key generation/serialization. Use this for conditional deduplication based on request context or parameters.

    const fetcher = withInflightDedup(fetchData, {
    shouldDedupe: (url, opts) => !opts?.bustCache
    });