Last active
June 7, 2020 05:07
-
-
Save Jack-Works/3ba26cb0326897ad9bdd64b70f7d5b98 to your computer and use it in GitHub Desktop.
Pause on exception, with catch, async version
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 sleep(ms) { | |
return new Promise((resolve) => setTimeout(resolve, ms)) | |
} | |
async function err() { | |
await sleep(200) | |
// debugger: pause on uncaught exception | |
// should pause on this | |
throw new Error("wow") | |
} | |
function err2() { | |
throw new Error("sync") | |
} | |
// How to implement this "exec" function?? | |
// React version only works for the sync call stack (IIRC) | |
// https://github.com/facebook/react/blob/4c7036e807fa18a3e21a5182983c7c0f05c5936e/packages/shared/invokeGuardedCallbackImpl.js#L31 | |
async function exec(f) { | |
return await f() | |
} | |
exec(err).catch((x) => console.warn(x.message)) // wow | |
exec(err2).catch((x) => console.warn(x.message)) // sync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, I resolved it. The solution is too cursed and I'm happy to find a better solution