1

Im using a promise for a child process that does not have it's own timeout. I've tried Promise Bluebird's race method, it is throwing but still hanging the console.

const done = () => Promise.delay(500).then(() => throw new Error('timeout')
const fire = () => Promise.race([promiseHangs(url), done()])
fire().then(console.log)

How can I resolve the promiseHangs promise and stop the async process from running?

ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
  • Might be relevant: [Setting a timeout for each promise within a `Promise.all()`](https://stackoverflow.com/questions/48577702/setting-a-timeout-for-each-promise-within-a-promise-all/48578424#48578424). – jfriend00 Feb 16 '18 at 04:33
  • The code you hsve posted is concerned with how the promise returned from `promiseHangs()` is used. Resolving that promise is all to do with how `promiseHangs()` is written. The question cannot be anwered. – Roamer-1888 Feb 16 '18 at 07:56

1 Answers1

1

The result of const done = () => Promise.delay(500).then(() => throw new Error('timeout') is a thrown error. You are better off returning an actually promise from that using Promise.reject('timeout')

According to the documentation, the Promise.any method will return the first result and won't allow a rejected value you to win.

So const fire = () => Promise.any([promiseHangs(url), done()]) should work.