mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 06:26:26 +00:00
18 lines
287 B
TypeScript
18 lines
287 B
TypeScript
|
interface Result<T = unknown> {
|
||
|
res: T;
|
||
|
}
|
||
|
|
||
|
export function memoize<T = unknown>(callback: () => T): () => T {
|
||
|
let memo: null | Result<T> = null;
|
||
|
|
||
|
return (): T => {
|
||
|
if (memo) {
|
||
|
return memo.res;
|
||
|
}
|
||
|
|
||
|
const res = callback();
|
||
|
memo = { res };
|
||
|
return res;
|
||
|
};
|
||
|
}
|