Created
January 8, 2018 04:37
-
-
Save nestoralonso/ab6c71f235f1990f840298f9d857c4c8 to your computer and use it in GitHub Desktop.
Useful snippets
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
// HOF to do an automatic catch over functions that return promises | |
const handleErrors = fn => (...args) => fn(...args).catch(err => console.error(`Ohh the horror ${err}`)) | |
// A buggy sleep | |
const riskySleep = (ms) => | |
new Promise((resolve, reject) => { | |
if (Math.random() < 0.7) { reject(ms) } | |
setTimeout(() => resolve(ms), ms) | |
}); | |
const safeSleep = handleErrors(riskySleep) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment