Handle very long timeouts in Hoek.wait() #373
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This enhances
Hoek.wait()
to properly handle timeouts of more than2^31 - 1
ms.The existing implementation makes no mention of the fact that it is based on
setTimeout()
and its inherent limitation of2^31 - 1
ms. As it is right now, any value larger than this (which equates to around 25 days), is treated as if1
was passed, and triggers aTimeoutOverflowWarning
from node:While fixing this, I also took the opportunity to support timeout values using
BigInt
numbers, which I think makes sense for a modern API.Note that the implementation now returns a never resolving
Promise
for exceptionally long timeout values (includingInfinity
), making it work similar toHoek.block()
.Alternatives considered
Update the docs to note the limitation, and immediately throw an error if passed values larger than
2^31 - 1
.The implementation could also be more accurate for longs waits, but it requires manually tracking elapsed time, which does not seem worth the effort. The API should still wait at least the time specified.