Posted 29 December 2012 - 08:12 AM
In parallel API, the function who do the multitask stuff is this:
Based on this function I'm writing my own multitask function:
They are very similar but my function stop the program until a event is fired because of the os.pullEventRaw at the end, and I don't know why this is not happening in the parallel API function.
My question is how to make the function don't wait for the event and why this is not happening in the other function.
function runUntilLimit( _routines, _limit )
local count = #_routines
local living = count
local tFilters = {}
local event, p1, p2, p3, p4, p5
while true do
for n=1,count do
local r = _routines[n]
if r then
if tFilters[r] == nil or tFilters[r] == event or event == "terminate" then
local ok, param = coroutine.resume( r, event, p1, p2, p3, p4, p5 )
if not ok then
error( param )
else
tFilters[r] = param
end
if coroutine.status( r ) == "dead" then
_routines[n] = nil
living = living - 1
if living <= _limit then
return n
end
end
end
end
end
for n=1,count do
local r = _routines[n]
if r and coroutine.status( r ) == "dead" then
_routines[n] = nil
living = living - 1
if living <= _limit then
return n
end
end
end
event, p1, p2, p3, p4, p5 = os.pullEventRaw( )
end
end
Based on this function I'm writing my own multitask function:
function start() -- TODO Make this local
local tFilters = {}
local event, p1, p2, p3, p4, p5
while true do
for i = 1, #tThreads, 1 do
r = tThreads[i]
if r ~= nil then
if tFilters[r] == nil or tFilters[r] == event or event == "terminate" then
local ok, param = coroutine.resume(r, event, p1, p2, p3, p4, p5)
if not ok then
yError(param)
else
tFilters[r] = param
end
end
end
if r and coroutine.status(r) == "dead" then
table.remove(tThreads, i)
if #tThreads <= 0 then
return i
end
end
end
for i = 1, #tThreads, 1 do
r = tThreads[i]
if r and coroutine.status(r) == "dead" then
table.remove(tThreads, i)
if #tThreads <= 0 then
return i
end
end
end
event, p1, p2, p3, p4, p5 = os.pullEventRaw( )
end
end
They are very similar but my function stop the program until a event is fired because of the os.pullEventRaw at the end, and I don't know why this is not happening in the parallel API function.
My question is how to make the function don't wait for the event and why this is not happening in the other function.