Class: Ffmprb::Util::Reader

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

Instance Attribute Summary

Attributes inherited from Thread

#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.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/ffmprb/util.rb', line 119

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



135
136
137
138
139
140
141
142
143
144
# File 'lib/ffmprb/util.rb', line 135

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