mirror of
https://git.shadowkat.net/izaya/OC-PsychOS2.git
synced 2024-11-13 00:27:00 -05:00
23 lines
513 B
Lua
23 lines
513 B
Lua
tTasks,nPid,nTimeout,cPid = {},1,1,0
|
|
function os.spawn(f,n)
|
|
tTasks[nPid] = {["c"]=coroutine.create(f),["n"]=n,["p"]=nPid}
|
|
for k,v in pairs(tTasks[cPid] or {}) do
|
|
tTasks[nPid][k] = tTasks[nPid][k] or v
|
|
end
|
|
nPid = nPid + 1
|
|
return nPid - 1
|
|
end
|
|
function sched()
|
|
while #tTasks > 0 do
|
|
local tEv = {computer.pullSignal(nTimeout)}
|
|
for k,v in pairs(tTasks) do
|
|
if coroutine.status(v.c) ~= "dead" then
|
|
cPid = k
|
|
coroutine.resume(v.c,table.unpack(tEv))
|
|
else
|
|
tTasks[k] = nil
|
|
end
|
|
end
|
|
end
|
|
end
|