Created
September 16, 2018 19:42
-
-
Save pixelsnob/17f784a403114068ab82a5cda8b9a7de 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
const pp = function() { | |
return new Promise((resolve, reject) => { | |
let r = (Math.round(Math.random() * 5, 0)); | |
if (r > 3) { | |
setTimeout(() => resolve(r), r * 1000); | |
} else { | |
reject(`${r} is not enough`); | |
} | |
}); | |
}; | |
pp().then((r) => console.log(r)) | |
.catch(err => console.error(err)) | |
.finally(() => console.log('always runs')); | |
(async function() { | |
try { | |
let r = await pp(); | |
console.log('await version: ' + r); | |
} catch (err) { | |
console.error('await error: ', err); | |
} finally { | |
console.log('await always runs'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment