class Proclib::Process
Runs a command, emitting output, state changes and exit status to the given channel
Constants
- Error
Attributes
channel[R]
command[R]
io_handlers[R]
wait_thread[R]
Public Class Methods
new(command, channel:)
click to toggle source
# File lib/proclib/process.rb, line 13 def initialize(command, channel:) @command, @channel, @state = command, channel, :ready end
Public Instance Methods
spawn()
click to toggle source
# File lib/proclib/process.rb, line 17 def spawn raise(Error, "Already started process") if @state != :ready @state = :started command.spawn output_emitter.start start_watch_thread end
Private Instance Methods
output_emitter()
click to toggle source
# File lib/proclib/process.rb, line 38 def output_emitter @output_emitter ||= CommandMonitor.new(command, channel: channel) end
start_watch_thread()
click to toggle source
# File lib/proclib/process.rb, line 30 def start_watch_thread @watch_thread ||= Thread.new do command.wait output_emitter.wait channel.emit(:exit, command.result) end end