Skip to content

Instantly share code, notes, and snippets.

@victorporof
Created June 30, 2022 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorporof/b6fd113317f4162b27861bfd353dc920 to your computer and use it in GitHub Desktop.
Save victorporof/b6fd113317f4162b27861bfd353dc920 to your computer and use it in GitHub Desktop.
// @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