Perf: reduce infra runtime costs

This commit is contained in:
SukkaW
2023-09-14 21:11:43 +08:00
parent 0a4c99ab0e
commit b42bd05ccf
23 changed files with 172 additions and 265 deletions

View File

@@ -1,3 +1,4 @@
// @ts-check
const path = require('path');
const { performance } = require('perf_hooks');
@@ -35,8 +36,21 @@ module.exports.traceAsync = traceAsync;
* @template T
* @param {string} __filename
* @param {() => Promise<T>} fn
* @returns {T}
* @returns {Promise<T>}
*/
module.exports.runner = async (__filename, fn) => {
return traceAsync(`⌛ [${path.basename(__filename, path.extname(__filename))}]`, fn);
};
/**
* @template T
* @param {string} __filename
* @param {() => Promise<T>} fn
*/
module.exports.task = (__filename, fn) => {
const taskName = path.basename(__filename, path.extname(__filename));
return () => {
console.log(`🏃 [${taskName}] Start executing`);
return traceAsync(`✅ [${taskName}] Executed successfully`, fn);
};
};