mirror of
https://github.com/SukkaW/Surge.git
synced 2026-02-02 03:51:53 +08:00
Perf: reduce infra runtime costs
This commit is contained in:
@@ -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);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user