UNPKG

sequence-request

Version:

A lightweight TypeScript library for handling request deduplication.

22 lines (20 loc) 1.03 kB
/** * RequestManager class for handling request deduplication. * Only the latest request's result will be returned, previous requests' results will be ignored. * Note: This does not actually cancel the underlying requests - they continue to execute. */ declare class RequestManager { /** Tracks the ID of the latest request to determine which request's result should be returned */ private latestRequestId; constructor(); /** * Wraps a function to add request deduplication functionality. * Only the most recent call to the wrapped function will return its result. * Previous calls will return null (for successful requests) or be ignored (for failed requests). * Note: The underlying requests are not cancelled - they continue to execute in the background. * @param requestFn - The function to wrap * @returns A wrapped function that ignores results from superseded requests */ wrap(requestFn: Function): (...args: unknown[]) => Promise<any>; } export { RequestManager };