Created
October 8, 2015 17:11
-
-
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."
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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