Class: Ffmprb::Util::Reader

Inherits:
Thread
  • Object
show all
Defined in:
lib/ffmprb/util.rb

Instance Attribute Summary

Attributes inherited from Thread

#backtrace, #name

Attributes included from ProcVis::Node

#_proc_vis

Instance Method Summary collapse

Methods inherited from Thread

#child_dies, #child_lives, join_children!, #join_children!, #live!, timeout_or_live

Methods included from ProcVis::Node

#proc_vis_edge, #proc_vis_name, #proc_vis_node

Constructor Details

#initialize(input, store: false, log_with: nil, log_as: Logger::DEBUG) ⇒ Reader

Returns a new instance of Reader.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ffmprb/util.rb', line 142

def initialize(input, store: false, log_with: nil, log_as: Logger::DEBUG)
  @output = ''
  @queue = Queue.new
  super "reader" do
    begin
      while s = input.gets
        Ffmprb.logger.log log_as, "#{log_with}: #{s.chomp}"  if log_with
        @output << s  if store
      end
      @queue.enq @output
    rescue Exception
      @queue.enq Error.new("Exception in a reader thread")
    end
  end
end

Instance Method Details

#readObject



158
159
160
161
162
163
164
165
166
167
# File 'lib/ffmprb/util.rb', line 158

def read
  case res = @queue.deq
  when Exception
    fail res
  when ''
    nil
  else
    res
  end
end