OpenComputerScripts/libs/libkeepup.lua
2019-01-07 22:20:32 +08:00

24 lines
558 B
Lua

-- LibKeepUp
-- Avoid 'too long without yielding'
-- Experimental.
local generator
if(os.sleep) then -- Oh! We are in OpenComputers
local computer=require('computer')
local __last_uptime=computer.uptime()
generator=function(sec)
return function()
local now=computer.uptime()
if(now-__last_uptime>=sec) then
os.sleep(0)
__last_uptime=now
end
end
end
else -- In Standard Lua
generator=function()
return function() end
end
end
return generator