Class FetchQueue

A queue to manage fetch requests with unique identification.

Useful to deduplicate concurrent network calls to the same URL.

const queue = new FetchQueue(fetch);
const [a, b] = await Promise.all([
queue.addRequest('https://example.com/data'),
queue.addRequest('https://example.com/data')
]);
// only one HTTP request is performed

Constructors

Methods

Constructors

  • Parameters

    • fetchFn: ((url: string, options?: RequestInit) => Promise<any>)

      A fetch function (e.g., node-fetch or window.fetch).

        • (url, options?): Promise<any>
        • Parameters

          • url: string
          • Optionaloptions: RequestInit

          Returns Promise<any>

    Returns FetchQueue

Methods

  • Adds a fetch request to the queue.

    Parameters

    • url: string

      The URL to fetch.

    • Optionaloptions: RequestInit

      Optional fetch options.

    Returns Promise<any>

    • A promise that resolves with the fetch response.