Last active
May 6, 2022 00:12
-
-
Save MaximumADHD/4ae7113f6ccfa666caa0c3991398e21a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Consider using Thread instead! | |
-- https://gist.github.com/CloneTrooper1019/538f0ab2541ef98912a2694dd8d274e7 | |
local RunService = game:GetService("RunService") | |
local threads = {} | |
RunService.Stepped:Connect(function () | |
local now = tick() | |
local resumePool | |
for thread, resumeTime in pairs(threads) do | |
-- Resume if we're reasonably close enough. | |
local diff = (resumeTime - now) | |
if diff < 0.005 then | |
if not resumePool then | |
resumePool = {} | |
end | |
table.insert(resumePool, thread) | |
end | |
end | |
if resumePool then | |
for _,thread in pairs(resumePool) do | |
threads[thread] = nil | |
coroutine.resume(thread, now) | |
end | |
end | |
end) | |
local function fastWait(t) | |
local t = tonumber(t) or 1 / 30 | |
local start = tick() | |
local thread = coroutine.running() | |
threads[thread] = start + t | |
-- Wait for the thread to resume. | |
local now = coroutine.yield() | |
return now - start, elapsedTime() | |
end | |
return fastWait |
This hides the whole enchilada for errors, beware!
``
local FastWait = require(script.Parent.FastWait)
print("Hizzo")
FastWait(1)
print("Hizza")
error("an error") -- Doesn't go to output
`` (unless I am using this wrong)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for releasing this, I never realized how sluggish the normal wait() function is!