Class: EventMachine::POpen3::Wrapper

Inherits:
Object
  • Object
show all
Includes:
EM::Deferrable
Defined in:
lib/em-popen3/popen3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, stream_callbacks) ⇒ Wrapper

Returns a new instance of Wrapper.



41
42
43
44
45
46
47
48
# File 'lib/em-popen3/popen3.rb', line 41

def initialize(cmd, stream_callbacks)
  @pipes = {}
  @stream_callbacks = stream_callbacks
  @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(cmd)
  @stdin_conn = EM.attach(@stdin, Handler, self, :stdin)
  @stdout_conn = EM.attach(@stdout, OutHandler, self, :stdout)
  @stderr_conn = EM.attach(@stderr, OutHandler, self, :stderr)
end

Instance Attribute Details

#pipesObject

Returns the value of attribute pipes.



39
40
41
# File 'lib/em-popen3/popen3.rb', line 39

def pipes
  @pipes
end

#stream_callbacksObject

Returns the value of attribute stream_callbacks.



39
40
41
# File 'lib/em-popen3/popen3.rb', line 39

def stream_callbacks
  @stream_callbacks
end

Instance Method Details

#kill(signal = 'TERM', wait = false) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/em-popen3/popen3.rb', line 54

def kill(signal='TERM', wait=false)
  Process.kill(signal, @wait_thr.pid)
  val = @wait_thr.value if wait
  @stdin_conn.close_connection
  @stdout_conn.close_connection
  @stderr_conn.close_connection
  return val
end

#send_data(data) ⇒ Object



50
51
52
# File 'lib/em-popen3/popen3.rb', line 50

def send_data(data)
  pipes[:stdin].send_data(data) if pipes.has_key?(:stdin)
end

#unbind(name) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/em-popen3/popen3.rb', line 63

def unbind(name)
  pipes.delete(name)
  remove_instance_variable("@"+name.to_s)
  if pipes.empty?
    err_code = @wait_thr.value
    err_code == 0 ? succeed : fail(err_code)
  end
end