Feature request: Infinity timeout
momocow opened this issue · comments
In the current version, although Infinity
is a valid value to the milliseconds
parameter,
typeof Infinity === 'number' && Infinity > 0 // true
it actually times out immediately both in browsers and Nodejs environment (tested on Chrome 76.0.3809.132 and Node v12.7.0).
You can take a look at the following snippet.
setTimeout(() => console.log("Infinity timeout"), Infinity);
setTimeout(() => console.log("Immediate timeout"));
// Infinity timeout
// Immediate timeout
Nodejs also output the following message.
(node:19336) TimeoutOverflowWarning: Infinity does not fit into a 32-bit signed integer.
Timeout duration was set to 1.
I understand that it is meaningless to use setTimeout
with Infinity
timeout, since the callback will never invoked if setTimeout
is implemented with really "infinity" timeout.
But as p-timeout, it's a timer waiting for a promise to be resolved, and thus we expected the infinity timeout for p-timeout means that no matter how long it takes to resolve the promise, we will wait.
So I suggest if the milliseconds
is Infinity
, simply fallback to original promise without timer wrapped, then the behavior is as expected.