Closed ericelliott closed 7 years ago
Handle the normal cancel error with a noop and then catch the success handler's error with .catch():
.catch()
const speculation = ( fn, cancel = Promise.reject('Cancelled') ) => new Promise((resolve, reject) => { const noop = () => {}; const handleCancel = ( onCancel ) => cancel.then( onCancel, noop ).catch(e => reject(e)); return fn(resolve, reject, handleCancel); });
Handle the normal cancel error with a noop and then catch the success handler's error with
.catch()
: