Files
recap/node_modules/@start9labs/start-sdk/base/lib/util/once.d.ts
T

15 lines
452 B
TypeScript

/**
* Wraps a function so it is only executed once. Subsequent calls return the cached result.
*
* @param fn - The function to execute at most once
* @returns A wrapper that lazily evaluates `fn` on first call and caches the result
*
* @example
* ```ts
* const getConfig = once(() => loadExpensiveConfig())
* getConfig() // loads config
* getConfig() // returns cached result
* ```
*/
export declare function once<B>(fn: () => B): () => B;