diff --git a/lib/listen/record.rb b/lib/listen/record.rb index ad374cec..6d18646a 100644 --- a/lib/listen/record.rb +++ b/lib/listen/record.rb @@ -97,16 +97,30 @@ def _fast_unset_path(dirname, basename) end end - def _fast_build_dir(remaining, symlink_detector) - entry = remaining.pop - children = entry.children # NOTE: children() implicitly tests if dir - symlink_detector.verify_unwatched!(entry) - children.each { |child| remaining << child } - add_dir(entry.record_dir_key) - rescue Errno::ENOTDIR - _fast_try_file(entry) - rescue SystemCallError, SymlinkDetector::Error - _fast_unset_path(entry.relative, entry.name) + def _fast_build_dir(remaining_, symlink_detector_) + thr_arr = [] + 5.times do + thr_arr << Thread.new(remaining_, symlink_detector_) do |remaining, symlink_detector| + begin + entry = remaining.pop(true) + rescue Exception + return + end + begin + children = entry.children # NOTE: children() implicitly tests if dir + symlink_detector.verify_unwatched!(entry) + children.each {|child| remaining << child} + add_dir(entry.record_dir_key) + rescue Errno::ENOTDIR + _fast_try_file(entry) + rescue SystemCallError, SymlinkDetector::Error + _fast_unset_path(entry.relative, entry.name) + end + end + end + thr_arr.each do |one| + one.join + end end def _fast_try_file(entry)