“task.wait should not be called on a thread that is already ‘deffered’ in the task library”
On my experience’s page, in the “Errors” tab I am seeing this warning show up many times. However, im not able to reproduce this error in studio, or in any game. So I am unsure how to prevent it?? The stack traces all point to several scripts that call task.wait(n).
I just don’t know where to go from here. Since im unable to see the error in studio, or in-game, I dont know how to resolve this.
I tried many different combinations of task.delay, task.defer, and task.wait and was not able to reproduce. I also tried pausing and resuming threads with coroutine. Still can’t reproduce.
For example, here is a screenshot where I highlighted the line number that is giving this error.
It is not running fine. I just finally joined a server and experienced the errors. Any and all threads that use the task libraries will not yield at all so the game INSTANTLY runs everything at once.
It gives all errors but the last line they all have in common, is the line below: local Decision, extraData = Token:makeDecision("TurnDecision",self.SettingsService.Settings.GameSettings.turnTime)
That function yields the running thread until the user makes a decision
So maybe the way I am yielding the thread is an issue? Idk
I really don’t have a clue why it is breaking all of the sudden as I haven’t touched any of that code as far as I can remember. That being said, this is how I am yielding threads:
function TimerClass:Wait()
if self:GetState() ~= "Running" then self:Resume() end
local currentThread = coroutine.running()
table.insert(self.YieldedThreads,currentThread)
return coroutine.yield()
end
And I am resuming my threads by calling task.defer(thread)
The thread is running in the same execution cycle that you’re calling task.defer in.
It seems to be a race condition type issue, the thread is possibly being resumed in a way you’re not expecting leading to this problem.
local thread = task.spawn(function()
coroutine.yield()
task.wait(0.5)
end)
print(coroutine.status(thread)) --> "suspended"
task.defer(thread)
coroutine.resume(thread) --> warning: task.wait should not be called on a thread that is already 'deferred' in the task library
Interesting! I re-visited the logic on my timer module. I believe there may have been a situation where I resumed the thread multiple times in the same process…thank you!
edit: After reworking the module there have been 0 errors in the last several hours. Thank you so much