class Proclib::OutputHandler
Emits events for the given io pipe with relevant tagging info
Constants
- Message
- READ_SIZE
Attributes
channel[R]
command[R]
type[R]
Public Class Methods
new(type, command, channel:)
click to toggle source
# File lib/proclib/output_handler.rb, line 50 def initialize(type, command, channel:) @type, @command, @channel = type, command, channel end
Public Instance Methods
kill()
click to toggle source
# File lib/proclib/output_handler.rb, line 62 def kill @thread.exit end
start()
click to toggle source
# File lib/proclib/output_handler.rb, line 54 def start @thread = Thread.new { monitor } end
wait()
click to toggle source
# File lib/proclib/output_handler.rb, line 58 def wait @thread.join end
Private Instance Methods
line_buffer()
click to toggle source
# File lib/proclib/output_handler.rb, line 80 def line_buffer @line_buffer ||= LineBuffer.new do |line| channel.emit(:output, Message.new(command.tag, type, line)) end end
monitor()
click to toggle source
# File lib/proclib/output_handler.rb, line 72 def monitor while s = pipe.read(READ_SIZE) line_buffer.write(s) end line_buffer.flush end
pipe()
click to toggle source
# File lib/proclib/output_handler.rb, line 68 def pipe @pipe ||= command.pipes[type] end