Last active
March 4, 2020 19:49
-
-
Save erming/27a2af15b156b6d7dcc64200f3e0ecae 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
async function withTimeout(fn, ms = 400) { | |
return new Promise(async (resolve, reject) => { | |
setTimeout(() => { | |
reject(); | |
}, ms); | |
resolve(await fn()); | |
}); | |
} | |
async function delay(ms = 0) { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
resolve(); | |
}, ms); | |
}); | |
} | |
withTimeout(() => delay(200)).then(_ => console.log("a")).catch(_ => console.log("b")); | |
withTimeout(() => delay(600)).then(_ => console.log("x")).catch(_ => console.log("y")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment