Class: Timmy::CommandStreamer

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ CommandStreamer

Returns a new instance of CommandStreamer.



12
13
14
15
# File 'lib/timmy/command_streamer.rb', line 12

def initialize(command)
  @command = command
  @queue = Queue.new
end

Class Method Details

.stream(command, &block) ⇒ Object



7
8
9
# File 'lib/timmy/command_streamer.rb', line 7

def stream(command, &block)
  self.new(command).stream(&block)
end

Instance Method Details

#stream(&block) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/timmy/command_streamer.rb', line 17

def stream(&block)
  Open3.popen3(*@command) do |stdin, stdout, stderr, wait_thr|
    start_readers(stdout: stdout, stderr: stderr)
    pop_lines_from_active_readers(block)
    join_readers()
  end
end