2023-01-22 19:44:23 +00:00
|
|
|
-- Wait should be accurate down to at least 10ms
|
2023-01-22 01:11:17 +00:00
|
|
|
|
2023-01-21 18:33:33 +00:00
|
|
|
local EPSILON = 1 / 100
|
|
|
|
|
2023-01-22 19:44:23 +00:00
|
|
|
local function test(expected: number)
|
2023-01-21 18:33:33 +00:00
|
|
|
local start = os.clock()
|
|
|
|
local returned = task.wait(expected)
|
|
|
|
local elapsed = (os.clock() - start)
|
|
|
|
local difference = math.abs(elapsed - returned)
|
|
|
|
if difference > EPSILON then
|
|
|
|
error(
|
|
|
|
string.format(
|
|
|
|
"Elapsed time diverged too much from argument!"
|
|
|
|
.. "\nGot argument of %.3fs and elapsed time of %.3fs"
|
|
|
|
.. "\nGot maximum difference of %.3fs and real difference of %.3fs",
|
2023-01-22 19:44:23 +00:00
|
|
|
expected,
|
2023-01-21 18:33:33 +00:00
|
|
|
elapsed,
|
|
|
|
EPSILON,
|
|
|
|
difference
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-22 19:44:23 +00:00
|
|
|
local function measure(duration: number)
|
2023-01-21 18:33:33 +00:00
|
|
|
for _ = 1, 5 do
|
|
|
|
test(duration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
measure(1 / 100)
|
|
|
|
measure(1 / 60)
|
|
|
|
measure(1 / 30)
|
|
|
|
measure(1 / 20)
|
|
|
|
measure(1 / 10)
|
2023-01-22 19:44:23 +00:00
|
|
|
|
|
|
|
-- Wait should work in other threads, too
|
|
|
|
|
|
|
|
local flag: boolean = false
|
|
|
|
coroutine.wrap(function()
|
|
|
|
task.wait(0.1)
|
|
|
|
flag = true
|
|
|
|
end)()
|
|
|
|
assert(flag, "Wait failed while in a coroutine")
|