Posted 05 October 2017 - 10:16 AM
Basically, I have a routine that simply prints a string, sleeps for 3 seconds and prints another string, then inevitably dies (don't worry, they don't mind it.)
The coroutine simply gets left as suspended. I'm pretty sure it's not supposed to be suspended for however long it feels like suspending for rather than 3 seconds. Any thoughts?
And here's the snippet of code in question:
and the routine code:
EDIT: Did some research, every time the process yields, it puts the coroutine in a permanent state of being suspended.
The coroutine simply gets left as suspended. I'm pretty sure it's not supposed to be suspended for however long it feels like suspending for rather than 3 seconds. Any thoughts?
And here's the snippet of code in question:
local tasks = {}
--#[snip snip]
function checkTasks()
for k,v in pairs(tasks) do
local success, resume = coroutine.resume(v.task)
if not resume then
print(v.taskID.." is dead")
table.remove(tasks, k)
break
else
print(v.taskID.." isn't dead ("..tostring(coroutine.status(v.task))..")")
coroutine.resume(v.task)
end
end
end
function new( _task )
if type(_task) == "function" then
local index = #tasks+1
tasks[index] = {}
tasks[index].taskID = index
tasks[index].task = coroutine.create(_task)
return tasks[index].taskID
else
error("invalid argument #1, expected function, got "..type(_task),2)
end
end
and the routine code:
function routine()
print("hello")
sleep(3)
print("goodbye!")
end
--# tasker = the coroutine system
tasker.new(routine())
while(true) do tasker.checkTasks() sleep(0) end
EDIT: Did some research, every time the process yields, it puts the coroutine in a permanent state of being suspended.
Edited on 05 October 2017 - 08:25 AM