RbxUtil icon indicating copy to clipboard operation
RbxUtil copied to clipboard

WaitFor module unusually long promise resolve time

Open MohhayScripts opened this issue 2 years ago • 1 comments

When coding with Roblox's own API, and using instance:WaitForChild(childName), you get a warning after 7 seconds that tells you that the yield is unusually long.

With the WaitFor module, that isn't a feature but instead, the default timeout is 60 seconds, and the timeout forces the promise's "yield" to reject and error.

This behavior is fine, and I am making the assumption that 60 seconds force timeout time was set with slow runtimes running WaitFor code in mind, however, as I was testing earlier today some code for my game that uses WaitFor, I realized that the WaitFor wasn't resolving in an expected time frame and I stopped the test almost immediately after and started to print debug the code.

This is not very ideal as it takes more time than it has to take, and if I were to wait 60 seconds at least before closing my game, I would have figured out the exact problem!

With Roblox's own API in mind, I think introducing an "unusual length warning" would do well for the WaitFor module, and being able to set this value somehow (not required but would be nice) would also be good. I think that 7 seconds unusual yielding time would work perfectly, as it has for Roblox throughout all these years.

I do not want to create a PR alongside this since WaitFor uses promise functionality which I have no experience in using, so instead I am making this issue with a code snippet of how unusual yield time warnings could be introduced.

I am hoping that someone can create a PR, or that Sleitnick can just update the module himself if he thinks this functionality can be introduced.

Here's the code snippet of how you can implement the functionality described above when creating a Promise.

local unusualYieldWarn = task.delay(7, function()
  warn("Unusual yielding time for Promise, etc")
end)

local promise = Promise.new(function(resolve)
  -- Do whatever you want in your promise here
  if promiseResolvedSomehow then
    task.cancel(unusualYieldWarn)
    resolve()
  end
end) 

MohhayScripts avatar Dec 19 '23 02:12 MohhayScripts

Below is an example of the warning that Roblox outputs after 7 seconds of yielding using a :WaitForChild().

image

It would probably be better to instead warn something along the lines of "Unusually long yield time" or so on for WaitFor's functionality.

MohhayScripts avatar Dec 19 '23 02:12 MohhayScripts