Created
June 30, 2022 05:17
-
-
Save victorporof/b6fd113317f4162b27861bfd353dc920 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
// @ts-ignore | |
const scheduleAsyncTask = console.scheduleAsyncTask ?? (() => {}); | |
// @ts-ignore | |
const startAsyncTask = console.startAsyncTask ?? (() => {}); | |
// @ts-ignore | |
const finishAsyncTask = console.finishAsyncTask ?? (() => {}); | |
interface ConsoleTask { | |
run<T>(f: () => T): T; | |
} | |
function scheduleTask(name: string): ConsoleTask { | |
const id = scheduleAsyncTask(name, true); | |
return { | |
run(f) { | |
try { | |
startAsyncTask(id); | |
const value = f(); | |
finishAsyncTask(id); | |
return value; | |
} catch (e) { | |
finishAsyncTask(id); | |
throw e; | |
} | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment