Class: Tlb::BalancerProcess::StreamPumper
- Inherits:
-
Object
- Object
- Tlb::BalancerProcess::StreamPumper
- Defined in:
- lib/tlb.rb
Instance Method Summary collapse
- #flush_stream ⇒ Object
-
#initialize(stream, file) ⇒ StreamPumper
constructor
A new instance of StreamPumper.
- #pump ⇒ Object
- #stop_pumping! ⇒ Object
Constructor Details
#initialize(stream, file) ⇒ StreamPumper
Returns a new instance of StreamPumper.
122 123 124 125 |
# File 'lib/tlb.rb', line 122 def initialize stream, file @stream, @file = stream, file @thd = Thread.new { pump } end |
Instance Method Details
#flush_stream ⇒ Object
135 136 137 138 139 |
# File 'lib/tlb.rb', line 135 def flush_stream File.open(ENV[@file], 'a') do |h| h.write(read) end end |
#pump ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/tlb.rb', line 127 def pump loop do data_available? && flush_stream Thread.current[:stop_pumping] && break sleep 0.1 end end |
#stop_pumping! ⇒ Object
141 142 143 144 |
# File 'lib/tlb.rb', line 141 def stop_pumping! @thd[:stop_pumping] = true @thd.join end |