-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delaying for more than ~24.8 days causes TimeoutOverflowWarning and immediate promise resolution #57
Comments
I think it would be best to just throw a human-friendly error if the value is too large and clearly document the behavior. We can also specially handle |
Why? Wouldn't supporting any values be simpler for users? This way they wouldn't need to remember that a limit exists. |
@papb A delay above 24 days makes no sense though. It's most likely a mistake and it would be better to fail loudly than to silently accept it. |
I found out about this bug because I needed a delay of more than 24 days. There definitely are (rare) situations in which it might be needed, and 24 days is quite a random threshold. I’m not saying I disagree with throwing an error though, I’m quite on the fence on this, but leaning towards accepting any positive integer. The “support any number” argument is more natural to me because as a user I don’t care about random |
Alright. I'm ok with supporting any number. I also like it when users don't have to care about implementation details. But I think the readme should note that the time will not be accurate because of clock drift and other factors and also that it's based on a suspending clock, not a continuous clock (meaning time will pause if the machine sleeps). |
The default implementation of setTimeout can only accept values within the range of positive signed 32-bit integers. Passing a timeout greater than (2^31)-1 milliseconds (0x7FFFFFFF) yields a TimeoutOverflowWarning and causes the runtime to ignore the specified timeout, assuming a value of 1ms (which by the way seems a dangerous default, I would have opted for using the maximum supported value or straight out throw an error).
This unexpected behavior is not documented in the README, but rather than documenting this quirk of the runtime I'd like to propose a solution: instead of relying on the bare setTimeout,
delay
could use a wrapped version of it. Something like this:The timeoutContext is passed by reference, therefore each time
defaultSetTimeout
gets called the timeout id gets updated, so thatdefaultClearTimeout
can always access the most recent value.The text was updated successfully, but these errors were encountered: