Skip to content

Instantly share code, notes, and snippets.

@dmarcuse
Created October 8, 2015 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmarcuse/f878fae3210770c0facd to your computer and use it in GitHub Desktop.
Save dmarcuse/f878fae3210770c0facd to your computer and use it in GitHub Desktop.
A safe version of ComputerCraft's sleep function - any events that occur while sleeping will be requeued so none are "dropped."
local function delay(seconds)
-- safe version of 'sleep' - will requeue dropped events
local timer = os.startTimer(seconds)
local q = {}
while true do
local data = {os.pullEvent()}
if data[1] == "timer" and data[2] == timer then
break
else
table.insert(q, data)
end
end
for i,v in ipairs(q) do
os.queueEvent(unpack(v))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment