@casual-simulation/aux-common
Version:
Common library for AUX projects
22 lines • 641 B
JavaScript
/**
* Calculates the result of the given function - caching it if needed.
* @param name The name of the function.
* @param func The function to cache.
* @param args The arguments that should be used to determine when to reuse the cached results
*/
export function cacheFunction(calc, name, func, ...args) {
if (!calc) {
return func();
}
let key = name;
for (let arg of args) {
key += `-${arg}`;
}
if (calc.cache.has(key)) {
return calc.cache.get(key);
}
const result = func();
calc.cache.set(key, result);
return result;
}
//# sourceMappingURL=BotCalculationContext.js.map