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.lua12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/command_queue.lua b/src/command_queue.lua
index 7f95d9b..861ccfc 100644
--- a/src/command_queue.lua
+++ b/src/command_queue.lua
@@ -35,13 +35,14 @@ command_queue = {}
command_queue.commands = {}
command_queue.current = nil
-function command_queue:enqueue(command, expected_response, timeout)
+function command_queue:enqueue(command, expected_response, requestor, timeout)
if(not command) then
log.printf(log.INFO, "ignoring empty command")
end
local new_cmd = {}
new_cmd.command = command
new_cmd.sent = false
+ new_cmd.requester = requester
if(expected_response and module_list.output.class.properties.type == defines.OUT_MODULE) then
log.printf(log.WARNING, "output module doesn't support responses, ignoring expected response");
else
@@ -96,12 +97,19 @@ function command_queue:check_timeout()
if(timer.cmp(timer.now(), self.current.expiration_time) == 1) then
log.printf(log.NOTICE, "command timed out")
+ if(self.current.requester) then
+ self.current.requester:process_timeout()
+ end
self:command_completed()
end
end
-function command_queue:command_completed()
+function command_queue:command_completed(response)
if(self.current == nil) then return end
+
+ if(response and self.current.requester) then
+ self.current.requester:process_response(response)
+ end
table.remove(self.commands, 1)
self.current = nil