2023-01-21 22:23:39 +00:00
|
|
|
-- Cancel should cancel any deferred or delayed threads
|
|
|
|
|
|
|
|
local flag: boolean = false
|
|
|
|
local thread = task.defer(function()
|
2023-01-24 00:13:18 +00:00
|
|
|
task.wait(0.1)
|
2023-01-21 22:23:39 +00:00
|
|
|
flag = true
|
|
|
|
end)
|
|
|
|
local thread2 = task.delay(0, function()
|
2023-01-24 00:13:18 +00:00
|
|
|
task.wait(0.1)
|
2023-01-21 22:23:39 +00:00
|
|
|
flag = true
|
|
|
|
end)
|
|
|
|
task.cancel(thread)
|
|
|
|
task.cancel(thread2)
|
2023-01-24 00:13:18 +00:00
|
|
|
task.wait(0.2)
|
2023-01-21 22:23:39 +00:00
|
|
|
assert(not flag, "Cancel should handle non-immediate threads")
|
|
|
|
|
|
|
|
-- Cancellation should be as immediate as possible
|
|
|
|
|
|
|
|
local flag2: number = 1
|
|
|
|
task.spawn(function()
|
2023-01-23 19:09:10 +00:00
|
|
|
task.wait(0.1)
|
2023-01-21 22:23:39 +00:00
|
|
|
flag2 = 2
|
2023-01-23 19:09:10 +00:00
|
|
|
task.wait(0.2)
|
2023-01-21 22:23:39 +00:00
|
|
|
flag2 = 3
|
|
|
|
end)
|
2023-01-23 19:09:10 +00:00
|
|
|
task.wait(0.2)
|
2023-01-21 22:23:39 +00:00
|
|
|
assert(flag2 == 2, "Cancel should properly handle yielding threads")
|