Browse Source

Realized event queueing never happens at the OS level, so last commit before tearing apart async and redoing a lot of stuff

master
BuildTools 12 months ago
parent
commit
ed7123d3ad
  1. 69
      coro.lua
  2. 3
      dhcp-server.lua
  3. 3
      dns-server.lua
  4. 0
      eeproms/eeprom-server.lua
  5. 0
      eeproms/eeprom-worker.lua
  6. 1
      eeproms/lua_bios.lua
  7. 12
      lib/async.lua

69
coro.lua

@ -1,69 +0,0 @@
local coroutine = require("coroutine")
local net = require("net")
local table = require("table")
function eventLoop(...)
-- Put in here in for later usage
local done = {}
-- Get running coroutines
local running = {...}
local canRun = true
local i = 1
while canRun do
while coroutine.status(running[i]) == "dead" do
table.insert(done, #done+1, table.remove(running, i))
if #running == 0 then
goto done
end
end
if #running == 0 then
canRun = false
else
_, pkt = coroutine.resume(running[i])
if pkt ~= nil then print("Received: "..pkt.msg) end
i = (i % #running) + 1
end
end
::done::
end
-- TODO finish this
function betterLoop(...)
-- Get running coroutines
local done = {}
local results = {}
local running = {...}
local canRun = true
local i = 1
while true do
local coro = running[i][1]
status, t = coroutine.resume(coro, slice(running[i], 2, #(running[i])))
if t ~= nil then
print(#t)
end
i = (i % #running) + 1
while coroutine.status(coro) == "dead" do
table.insert(results, #results+1, table.remove(running, i)) -- can do this better
if #running == 0 then
goto done
end
end
end
::done::
return results
end
function simple()
print("Foo")
coroutine.yield()
print("Done")
return "a"
end
local coro = coroutine.create(simple)
betterLoop({coro})

3
dhcp-server.lua

@ -1,3 +0,0 @@
local dhcp = require("dhcp")
dhcp.startServer()

3
dns-server.lua

@ -1,3 +0,0 @@
local dns = require("dns")
dns.startServer()

0
eeprom-server.lua → eeproms/eeprom-server.lua

0
eeprom-worker.lua → eeproms/eeprom-worker.lua

1
eeproms/lua_bios.lua

@ -1,3 +1,4 @@
-- Stolen from OpenComputers
local init
do
local component_invoke = component.invoke

12
lib/async.lua

@ -36,8 +36,10 @@ function async.pullFiltered(...)
if blocking then return event.pullFiltered(f, ...) end
repeat
print("Yielding")
coroutine.yield()
tmp = {event.pullFiltered(.01, f, ...)}
tmp = {event.pullFiltered(.05, f, ...)}
print("Pulled?")
until #tmp > 0
else
local timeout = nil
@ -68,7 +70,7 @@ function async.pullFiltered(...)
repeat
coroutine.yield()
tmp = {event.pullFiltered(.01, g, table.unpack(args))}
tmp = {event.pullFiltered(.05, g, table.unpack(args))}
until #tmp > 0 or computer.uptime() - start >= timeout
else
-- Check if not in a coroutine
@ -78,7 +80,7 @@ function async.pullFiltered(...)
repeat
coroutine.yield()
tmp = {event.pullFiltered(.01, g, table.unpack(args))}
tmp = {event.pullFiltered(.05, g, table.unpack(args))}
until #tmp > 0
end
else
@ -90,7 +92,7 @@ function async.pullFiltered(...)
repeat
coroutine.yield()
tmp = {event.pullFiltered(.01, f, table.unpack(args))}
tmp = {event.pullFiltered(.05, f, table.unpack(args))}
until #tmp > 0 or computer.uptime() - start >= timeout
else
-- Check if not in a coroutine
@ -100,7 +102,7 @@ function async.pullFiltered(...)
repeat
coroutine.yield()
tmp = {event.pullFiltered(.01, f, table.unpack(args))}
tmp = {event.pullFiltered(.05, f, table.unpack(args))}
until #tmp > 0
end
end

Loading…
Cancel
Save