diff --git a/src/models/analyzer.cr b/src/models/analyzer.cr index 11c67a31..3387502d 100644 --- a/src/models/analyzer.cr +++ b/src/models/analyzer.cr @@ -12,6 +12,7 @@ class Analyzer @is_debug : Bool @is_color : Bool @is_log : Bool + @options : Hash(Symbol, String) def initialize(options : Hash(Symbol, String)) @base_path = options[:base] @@ -22,6 +23,7 @@ class Analyzer @is_debug = str_to_bool(options[:debug]) @is_color = str_to_bool(options[:color]) @is_log = str_to_bool(options[:nolog]) + @options = options @logger = NoirLogger.new @is_debug, @is_color, @is_log end @@ -53,22 +55,35 @@ class FileAnalyzer < Analyzer end def analyze - begin - Dir.glob("#{base_path}/**/*") do |path| - next if File.directory?(path) - @@hooks.each do |hook| - file_results = hook.call(path, @url) - if !file_results.nil? - file_results.each do |file_result| - @result << file_result + channel = Channel(String).new + spawn do + Dir.glob("#{base_path}/**/*") do |file| + channel.send(file) + end + end + + @options[:concurrency].to_i.times do + spawn do + loop do + begin + path = channel.receive + next if File.directory?(path) + @@hooks.each do |hook| + file_results = hook.call(path, @url) + if !file_results.nil? + file_results.each do |file_result| + @result << file_result + end + end end + rescue e + logger.debug e end end end - rescue e - logger.debug e end + Fiber.yield @result end end