Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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)
Add Comment
Please, Sign In to add comment