We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ade4b2b commit 39c75bbCopy full SHA for 39c75bb
data/shared/citizen/scripting/lua/scheduler.lua
@@ -1,4 +1,10 @@
1
-local threads = {}
+local newThreads = {}
2
+local threads = setmetatable({}, {
3
+ -- This circumvents undefined behaviour in "next" (and therefore "pairs")
4
+ __newindex = newThreads,
5
+ -- This is needed for CreateThreadNow to work correctly
6
+ __index = newThreads
7
+})
8
9
--[[
10
@@ -97,6 +103,11 @@ SetTimeout = Citizen.SetTimeout
97
103
Citizen.SetTickRoutine(function()
98
104
local curTime = GetGameTimer()
99
105
106
+ for coro, thread in pairs(newThreads) do
107
+ rawset(threads, coro, thread)
108
+ newThreads[coro] = nil
109
+ end
110
+
100
111
for coro, thread in pairs(threads) do
101
112
if curTime >= thread.wakeTime then
102
113
resumeThread(coro)
0 commit comments