Created
November 28, 2023 08:27
-
-
Save hi-ogawa/6b5a2b1a72fc34174c4fcf297fb528aa to your computer and use it in GitHub Desktop.
wrapConsoleTimeAsync.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wrapConsoleTimeAsync<F extends (...args: any[]) => any>(f: F) { | |
const wrapper = async function (this: any, ...args: any[]) { | |
const id = Math.random().toString(36).slice(2).padStart(12, "0"); | |
const label = `${f.name}:${id}`; | |
globalThis.console.time(label); | |
try { | |
return await f.apply(this, args); | |
} finally { | |
globalThis.console.timeEnd(label); | |
} | |
} | |
return wrapper as F; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment