lib/nonnative/pool.rb in nonnative-1.3.0 vs lib/nonnative/pool.rb in nonnative-1.4.0

- old
+ new

@@ -20,38 +20,40 @@ attr_reader :configuration def processes @processes ||= configuration.processes.map do |d| - [Nonnative::System.new(d), Nonnative::Port.new(d)] + [Nonnative::Command.new(d), Nonnative::Port.new(d)] end end def servers @servers ||= configuration.servers.map do |d| [d.klass.new(d.port), Nonnative::Port.new(d)] end end - def process_all(all, pr_method, po_method, &block) - prs = [] - ths = [] + def process_all(all, type_method, port_method, &block) + types = [] + pids = [] + threads = [] - all.each do |pr, po| - prs << pr.send(pr_method) - ths << Thread.new { po.send(po_method) } + all.each do |type, port| + types << type + pids << type.send(type_method) + threads << Thread.new { port.send(port_method) } end - ThreadsWait.all_waits(*ths) + ThreadsWait.all_waits(*threads) - pos = ths.map(&:value) + ports = threads.map(&:value) - yield_results(prs, pos, &block) + yield_results(types, pids, ports, &block) end - def yield_results(prs, pos) - prs.zip(pos).each do |id, result| - yield id, result + def yield_results(all, pids, ports) + all.zip(pids, ports).each do |type, id, result| + yield type.name, id, result end end end end