es-next-tools
Version:
A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.
19 lines (18 loc) • 846 B
TypeScript
import type { AnyFunction } from '..';
/**
* Creates a memoized version of an asynchronous function.
* @param {AnyFunction} fn - The asynchronous function to memoize.
* @param {number} [expirationTime=60000] - Time in milliseconds before cache expires.
* @returns A memoized version of the input function.
* @example
* const memoizedFetch = memoizeAsync(async (url: string) => {
* const response = await fetch(url);
* return response.json();
* });
*
* // First call will fetch data
* const data1 = await memoizedFetch('https://api.example.com/data');
* // Second call with the same URL will return cached data
* const data2 = await memoizedFetch('https://api.example.com/data');
*/
export declare function memoizeAsync<T extends AnyFunction>(fn: T, expirationTime?: number): (...args: Required<Parameters<T>>) => Promise<any>;