diff --git a/bc.lua b/bc.lua index fbf9d594829a..fa03de9dd7e1 100644 --- a/bc.lua +++ b/bc.lua @@ -1,5 +1,4 @@ local uuid = require("uuid") -local computer = require("computer") local bit32 = require("bit32") local Version = {0, 1} @@ -31,6 +30,18 @@ local Query = { Below = setmetatable({ty=0x424c4f, invalid=true}, query_param), } +-- Helpers ---------------------------------------------------------------- {{{ +local clock -- A monotonically increasing timer for timeout calculation +do + local status, computer = pcall(require, "computer") + if status and computer.uptime ~= nil then + clock = computer.uptime + else + clock = os.clock + end +end +-- }}} + -- Network ---------------------------------------------------------------- {{{ local Network = { default_port = bit32.bor(0xBC00, bit32.lshift(Version[1], 4), Version[2]), @@ -190,11 +201,11 @@ function BaseControl:finalize(waits, timeout) end end - local tstart = computer.uptime() + local tstart = clock() local timeout_remaining = timeout while num_remaining > 0 do if timeout ~= nil then - timeout_remaining = timeout - (computer.uptime() - tstart) + timeout_remaining = timeout - (clock() - tstart) if timeout_remaining <= 0 then error("timeout") end