Class: Parasort::Molecule
- Inherits:
-
Object
- Object
- Parasort::Molecule
- Defined in:
- lib/parasort.rb
Constant Summary collapse
- MOLECULE_RATE =
ENV['PARASORT_MOLECULE_RATE'].to_i.yield_self{ |n| n > 0 ? n : 10000 }
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(dir, files) ⇒ Molecule
constructor
A new instance of Molecule.
- #move_to_dir(dir) ⇒ Object
Constructor Details
#initialize(dir, files) ⇒ Molecule
Returns a new instance of Molecule.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/parasort.rb', line 95 def initialize(dir, files) @done = false @lock = Mutex.new @cond = ConditionVariable.new @range = files.map(&:range).flatten.minmax @path = File.join(dir, @range.join('_')) @dir = dir Thread.new(files.freeze) do |fs| @lock.synchronize do Process.wait(fork{ _merge(fs) }) @done = true @cond.broadcast end end end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
91 92 93 |
# File 'lib/parasort.rb', line 91 def path @path end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
91 92 93 |
# File 'lib/parasort.rb', line 91 def range @range end |
Instance Method Details
#each(&block) ⇒ Object
119 120 121 122 |
# File 'lib/parasort.rb', line 119 def each(&block) wait_for_done File.foreach(@path, &block) end |
#move_to_dir(dir) ⇒ Object
113 114 115 116 117 |
# File 'lib/parasort.rb', line 113 def move_to_dir(dir) wait_for_done FileUtils.mv(@path, dir) @path = File.join(dir, File.basename(@path)) end |