File size: 213 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/**
* @template T
* @param {() => T} fn
*/
export function once(fn) {
let done = false;
/** @type T */
let result;
return () => {
if (done) return result;
done = true;
return (result = fn());
};
}
|