Comparison

util/async.lua @ 8602:9901deadc068

util.async: Fix order of statements so queue count makes more sense
author Matthew Wild <mwild1@gmail.com>
date Fri, 16 Mar 2018 17:12:09 +0000
parent 8601:ce5b16e13573
child 8603:dc5f3302a642
comparison
equal deleted inserted replaced
8601:ce5b16e13573 8602:9901deadc068
106 end 106 end
107 107
108 -- Add a task item for the runner to process 108 -- Add a task item for the runner to process
109 function runner_mt:run(input) 109 function runner_mt:run(input)
110 if input ~= nil then 110 if input ~= nil then
111 table.insert(self.queue, input);
111 self:log("debug", "queued new work item, %d items queued", #self.queue); 112 self:log("debug", "queued new work item, %d items queued", #self.queue);
112 table.insert(self.queue, input);
113 end 113 end
114 if self.state ~= "ready" then 114 if self.state ~= "ready" then
115 -- The runner is busy. Indicate that the task item has been 115 -- The runner is busy. Indicate that the task item has been
116 -- queued, and return information about the current runner state 116 -- queued, and return information about the current runner state
117 return true, self.state, #self.queue; 117 return true, self.state, #self.queue;
174 end 174 end
175 175
176 -- Add a task item to the queue without invoking the runner, even if it is idle 176 -- Add a task item to the queue without invoking the runner, even if it is idle
177 function runner_mt:enqueue(input) 177 function runner_mt:enqueue(input)
178 table.insert(self.queue, input); 178 table.insert(self.queue, input);
179 self:log("debug", "queued new work item, %d items queued", #self.queue);
179 end 180 end
180 181
181 function runner_mt:log(level, fmt, ...) 182 function runner_mt:log(level, fmt, ...)
182 return log(level, "[runner %s] "..fmt, self.id, ...); 183 return log(level, "[runner %s] "..fmt, self.id, ...);
183 end 184 end