Open haquezameer opened 3 years ago
Sure. That sounds useful.
@sindresorhus
what do you think about the resolved value of { started: true/false }
?. While it may not be useful for everyone, this came in handy when people want to explicitly assert whether request succeeded/failed, especially when using the timeout.
I think it should rather reject the promise when it times out.
Should use a custom error, like done here: https://github.com/sindresorhus/p-timeout/blob/4f86930f75d1565927790ab70b4ac643e47007fc/index.js#L3-L8
With the current system, a req is retried infinitely until we get a success response. Accepting a timeout would be good to break the loop of retrying.
Faced this recently when writing a few jest tests, where I wanted the request to succeed but only wait for a certain time and let the request timeout after that.
Something like this?