Last active
April 30, 2023 13:13
-
-
Save arn4v/cb175c397c98a3547ab1c33a9eef00fa to your computer and use it in GitHub Desktop.
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
type AnyPromiseFunction = (...params: any[]) => Promise<any>; | |
export function withPerformanceMonitoring< | |
T extends AnyPromiseFunction, | |
ReturnAwaited = Awaited<ReturnType<T>> | |
>(name: string, func: T): T { | |
const wrapped = async (...params: Parameters<T>): Promise<ReturnAwaited> => { | |
const timerName = `Loader performance: ${name}`; | |
console.time(timerName); | |
const data: ReturnAwaited = await func(...params); | |
console.timeEnd(timerName); | |
return data; | |
}; | |
return wrapped as T; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment