kinetex - v1.0.0-rc.1
    Preparing search index...

    Class DedupMap<T>

    DedupMap manages in-flight promises keyed by a request fingerprint. It is transport-agnostic — pass any async factory function.

    Type Parameters

    • T = unknown
    Index

    Constructors

    Accessors

    • get hits(): number

      Number of requests that shared an in-flight or windowed response.

      Returns number

    • get misses(): number

      Number of requests that triggered a real network call.

      Returns number

    • get inFlightCount(): number

      Number of currently in-flight requests.

      Returns number

    • get keys(): string[]

      All currently tracked keys (in-flight + window).

      Returns string[]

    Methods

    • Execute factory for the given method/url, or return the in-flight promise if one already exists for the same key.

      Parameters

      • method: string

        HTTP method

      • url: string

        Request URL (fully resolved)

      • factory: () => Promise<T>

        Async function that performs the actual work

      • Optionalheaders: Record<string, string>

        Optional headers included in the key (not deduplicated by default!)

      • OptionalwindowMs: number

        Optional per-key TTL override for this specific call. Uses the default windowMs if not provided.

      • Optionalsignal: AbortSignal

        Optional abort signal for this specific request. Falls back to the global signal from DedupOptions if not provided.

      Returns Promise<T>

      If factory throws, the error is propagated to all concurrent waiters sharing the same promise. The entry is removed on error, so subsequent callers will trigger a fresh factory call.

      Thread-safety: In single-threaded JavaScript, the synchronous inflight.get(key) check is atomic - there's no race condition between checking for an existing entry and creating a new one. The first caller becomes the "leader" and all subsequent callers within the same tick share the same promise.

      Note: The default keyFn does NOT include headers in the deduplication key. Two requests with different auth tokens to the same URL will NOT be deduplicated unless you provide a custom keyFn that includes headers.

    • Get comprehensive deduplication statistics.

      NOTE: inFlightCount and trackedKeys reflect snapshot time; entries may resolve asynchronously between sampling and return (non-blocking, acceptable).

      Returns {
          hits: number;
          misses: number;
          totalRequests: number;
          hitRate: number;
          inFlightCount: number;
          trackedKeys: number;
      }

      Snapshot containing hits, misses, totalRequests, hitRate (0–1), inFlightCount, and trackedKeys.

      • hits: number

        Number of requests that shared an in-flight or windowed response.

      • misses: number

        Number of requests that triggered a real network call.

      • totalRequests: number

        Total number of requests (hits + misses).

      • hitRate: number

        Hit rate ratio (0–1).

      • inFlightCount: number

        Number of currently in-flight requests.

      • trackedKeys: number

        Number of tracked keys (in-flight + window).

    • Reset metrics counters.

      Returns void

    • Clear all in-flight entries (does NOT cancel their underlying promises).

      Returns void

    • Manually invalidate a specific key. Removes the entry from the dedup map and clears any pending timeout.

      Parameters

      • key: string

        The key to invalidate

      Returns boolean

      true if key was found and removed

    • Destroy the dedup map - clears all entries and cancels all timeouts. Use this when the dedup map is no longer needed to prevent memory leaks.

      Returns void