Check argument against negative sleep duration
This commit is contained in:
parent
d5e85f2c30
commit
505364a661
@ -36,7 +36,7 @@ impl lb_tasklib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async extern "Lua-C" fn sleep(ms: f64) {
|
pub async extern "Lua-C" fn sleep(ms: f64) {
|
||||||
sleep(Duration::from_secs_f64(ms / 1000.)).await;
|
sleep(Duration::from_secs_f64(ms.max(0.) / 1000.)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern "Lua" fn spawn(f: function, ...) -> lb_task {
|
pub extern "Lua" fn spawn(f: function, ...) -> lb_task {
|
||||||
|
@ -111,6 +111,11 @@ describe("spawn", function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
describe("sleep", function()
|
describe("sleep", function()
|
||||||
|
test("invalid arg", function()
|
||||||
|
assert(not pcall(task.sleep, "invalid"))
|
||||||
|
task.sleep(-1) -- negative sleep should just become 0ms
|
||||||
|
end)
|
||||||
|
|
||||||
test("sleep is asynchronous", function()
|
test("sleep is asynchronous", function()
|
||||||
local value
|
local value
|
||||||
spawn(function()
|
spawn(function()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user