Guest User

Untitled

a guest
Jan 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. // HOF to do an automatic catch over functions that return promises
  2. const handleErrors = fn => (...args) => fn(...args).catch(err => console.error(`Ohh the horror ${err}`))
  3.  
  4. // A buggy sleep
  5. const riskySleep = (ms) =>
  6. new Promise((resolve, reject) => {
  7. if (Math.random() < 0.7) { reject(ms) }
  8. setTimeout(() => resolve(ms), ms)
  9. });
  10.  
  11. const safeSleep = handleErrors(riskySleep)
Add Comment
Please, Sign In to add comment