summaryrefslogtreecommitdiff
path: root/src/command_queue.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/command_queue.lua')
-rw-r--r--src/command_queue.lua15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/command_queue.lua b/src/command_queue.lua
index a1aa383..2bb34c6 100644
--- a/src/command_queue.lua
+++ b/src/command_queue.lua
@@ -45,8 +45,10 @@ function command_queue:enqueue(command, expected_response, timeout)
new_cmd.command = command
new_cmd.sent = false
new_cmd.expected_response = expected_response
- new_cmd.timeout = timeout
-
+ if(timeout) then
+ new_cmd.timeout = timer.new(timeout)
+ end
+
table.insert(self.commands, new_cmd)
end
@@ -69,6 +71,9 @@ function command_queue:command_sent()
if(self.current == nil) then return end
self.current.sent = true
+ if(self.current.timeout) then
+ self.current.expiration_time = timer.add(timer.now(), self.current.timeout)
+ end
if(self.current.expected_response) then
return self.current.expected_response
end
@@ -78,6 +83,12 @@ end
function command_queue:check_timeout()
if(self.current == nil or not self.current.sent) then return end
+ if(not self.current.expiration_time) then return end
+
+ if(timer.cmp(timer.now(), self.current.expiration_time) == 1) then
+ log.printf(log.NOTICE, "command timed out")
+ self:command_completed()
+ end
end
function command_queue:command_completed()