Skip to content

Instantly share code, notes, and snippets.

@nestoralonso
Created January 8, 2018 04:37
Show Gist options
  • Save nestoralonso/ab6c71f235f1990f840298f9d857c4c8 to your computer and use it in GitHub Desktop.
Save nestoralonso/ab6c71f235f1990f840298f9d857c4c8 to your computer and use it in GitHub Desktop.
Useful snippets
// 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