Calling task.delay(t, f) where t is either math.huge or a NaN will cause function f to be called immediately. Examples:
local t = tick()
task.delay(math.sqrt(-1), function() print(tick() - t) end)
task.delay(math.huge, function() print(tick() - t) end)
This prints:
0.015317916870117188
0.015427589416503906
I am not sure what the expected behavior would be, but especially in the case of math.huge being supplied as the duration parameter, I would expect one of the following behaviors instead:
An error or warning is thrown for supplying an invalid number.
The function is never called as it’s being delayed forever.
If this behavior turns out to be intended there should be a warning at the minimum.
We wanted the task library to be a drop in replacement for the existing scheduling globals so we could eventually deprecate them with clear migration instructions. This meant that we carried over some of their logic in the process leading to behavior like this. Amusingly enough, I actually made a note about this particular case at the time but we left it as is for consistency.
So, the tl;dr is that this is intended behavior but we’ll look at adding a warning so users aren’t surprised by this.
Hi there, I’ve added a warning when task.delay is called where t is NaN or math.huge/Infinity, warning you that t will default to zero. Thanks for the report!