Ensure spawn order is consistent
This commit is contained in:
parent
8443c44671
commit
3a7f2366e4
@ -45,6 +45,26 @@ describe("spawn", function()
|
|||||||
end, 5, 4, nil, 3, nil):await())
|
end, 5, 4, nil, 3, nil):await())
|
||||||
assert(res.n == 3 and res[1] == 1 and res[2] == 3 and res[3] == nil)
|
assert(res.n == 3 and res[1] == 1 and res[2] == 3 and res[3] == nil)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
test("order is consistent", function()
|
||||||
|
-- all tasks spawned in one batch should be resumed in the spawn order
|
||||||
|
local tasks, nums = {}, {}
|
||||||
|
for i = 1, 10 do
|
||||||
|
table.insert(
|
||||||
|
tasks,
|
||||||
|
spawn(function()
|
||||||
|
table.insert(nums, i)
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
for i = 10, 1, -1 do
|
||||||
|
tasks[i]:await()
|
||||||
|
end
|
||||||
|
assert(#nums == 10)
|
||||||
|
for i = 1, 10 do
|
||||||
|
assert(nums[i] == i)
|
||||||
|
end
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("sleep", function()
|
describe("sleep", function()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user