Class: Frypan::Tuner::RecordingProcess

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

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ RecordingProcess

Returns a new instance of RecordingProcess.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/frypan/tuner.rb', line 4

def initialize(command)
  @reader, writer = IO.pipe
  @pid = Process.spawn(command, :err => writer, :out => writer)
  @mutex = Mutex.new
  @logs = []
  Thread.new{
    while IO::select([@reader])
      @mutex.synchronize{
        @logs << @reader.gets.chomp
      }
    end
  }
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/frypan/tuner.rb', line 18

def finished?
  @finished ||= Process.waitpid2(@pid, Process::WNOHANG)
end

#get_logObject



22
23
24
25
26
27
28
29
# File 'lib/frypan/tuner.rb', line 22

def get_log
  res = []
  @mutex.synchronize{
    res = @logs.dup
    @logs = []
  }
  res
end