mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Improve task.cancel unit test
This commit is contained in:
parent
bd162a9bd6
commit
fcf59455db
1 changed files with 17 additions and 13 deletions
|
@ -2,26 +2,30 @@
|
|||
|
||||
local flag: boolean = false
|
||||
local thread = task.defer(function()
|
||||
task.wait(0.1)
|
||||
flag = true
|
||||
end)
|
||||
local thread2 = task.delay(0, function()
|
||||
task.wait(0.1)
|
||||
flag = true
|
||||
end)
|
||||
task.cancel(thread)
|
||||
task.cancel(thread2)
|
||||
task.wait(0.2)
|
||||
assert(not flag, "Cancel should handle non-immediate threads")
|
||||
|
||||
-- Cancellation should be as immediate as possible
|
||||
|
||||
local flag2: number = 1
|
||||
task.spawn(function()
|
||||
task.wait(0.1)
|
||||
flag2 = 2
|
||||
assert(not flag, "Cancel should handle deferred threads")
|
||||
|
||||
local flag2: boolean = false
|
||||
local thread2 = task.delay(0, function()
|
||||
flag2 = true
|
||||
end)
|
||||
task.cancel(thread2)
|
||||
task.wait(0.1)
|
||||
assert(not flag2, "Cancel should handle deferred threads")
|
||||
|
||||
-- Cancellation should work with yields in spawned threads
|
||||
|
||||
local flag3: number = 1
|
||||
local thread3 = task.spawn(function()
|
||||
task.wait(0.1)
|
||||
flag3 = 2
|
||||
task.wait(0.2)
|
||||
flag2 = 3
|
||||
flag3 = 3
|
||||
end)
|
||||
task.wait(0.2)
|
||||
assert(flag2 == 2, "Cancel should properly handle yielding threads")
|
||||
task.cancel(thread3)
|
||||
task.wait(0.2)
|
||||
assert(flag3 == 2, "Cancel should properly handle yielding threads")
|
||||
|
|
Loading…
Reference in a new issue