not quite a “wait”, but there’s task.defer
it can go pretty fast for some odd reason that i don’t know about
downside is that you can’t stack defers past 80 defers
for some reason 80 defers is still much less than 1/60th of a second (at least in the server)
if we add in parallel coding, you can use this hacky method with task.desynchronize and task.synchronize to bypass this defer limit
funny
@Linex_404’s example isn’t actual parallel, it’s “threading”. Basically, the task scheduler will run threads one after the other, so when one thread yields, another thread starts execution, and this gives the impression that threads are running independent of each other as if they were in “parallel”. However, only 1 thread can run at a time, so different threads still run in serial, but they don’t block each other
With parallel lua, you have multiple cpu threads doing work at the exact same time
The two are often confused (or it is unclear which one is being talked about), sometimes because people don’t understand it, but also because the terminology between the two overlap, which makes it quite confusing
task.defer, puts a function onto the next engine resumption step, (not necessarily heartbeat). it sometimes runs within the same step as well depending on how much work was done
but it can cause stack overflows as its faster than the stack is swept so be careful using it.
cc. @Linex_404 Roblox is single threaded, resumed coroutines run when the active one yields (pauses from a function like task.wait).
task.wait() is more precise then the wait() function, so you should use that instead. In regards to your question in what is the fastest “wait” function that yields depends on what you are trying to do. For example, if you are trying to create frame-precise actions you can use game:GetService("RunService").RenderStepped which fires every time before a frame renders.
local function FastWait()
-- the fastest wait function
end
local clock = os.clock()
FastWait()
print("Waited", string.format("%.7f", os.clock() - clock), "seconds")
this should be the fastest wait function
for me this prints Waited 0.0000005 seconds
I don’t think its possible to make it any faster