Class: Tlb::BalancerProcess::StreamPumper

Inherits:
Object
  • Object
show all
Defined in:
lib/tlb.rb

Instance Method Summary collapse

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_streamObject



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

#pumpObject



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