Skip to content

Instantly share code, notes, and snippets.

@bmeck
Created September 13, 2019 14:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bmeck/e9e9d7b5bc0295a3cc1f0ea6cea138f6 to your computer and use it in GitHub Desktop.
Save bmeck/e9e9d7b5bc0295a3cc1f0ea6cea138f6 to your computer and use it in GitHub Desktop.
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