Created
September 13, 2019 14:43
-
-
Save bmeck/e9e9d7b5bc0295a3cc1f0ea6cea138f6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 doSomething() { | |
await timeout(2000); | |
} | |
function timeout(ms) { | |
return new Promise((res,rej) => setTimeout(rej,ms)); | |
} | |
Promise.race([ | |
doSomething(), | |
timeout(1000) | |
]) | |
.then( () => console.log('success') , () => console.log('failure') ); | |
timeout(3000).catch( () => { | |
console.log(process._getActiveHandles()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment