Class: Cod::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/cod/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, serializer = nil) ⇒ Process

Returns a new instance of Process.



5
6
7
8
9
# File 'lib/cod/process.rb', line 5

def initialize(command, serializer=nil)
  @serializer = serializer || SimpleSerializer.new

  run(command)
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



3
4
5
# File 'lib/cod/process.rb', line 3

def pid
  @pid
end

Instance Method Details

#channelObject



19
20
21
# File 'lib/cod/process.rb', line 19

def channel
  @pipe
end

#killObject



23
24
25
# File 'lib/cod/process.rb', line 23

def kill
  ::Process.kill :TERM, @pid
end

#run(command) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/cod/process.rb', line 11

def run(command)
  @pipe = Cod.bidir_pipe(@serializer)
  
  @pid = ::Process.spawn(command, 
    :in => @pipe.w.r, 
    :out => @pipe.r.w)
end

#terminateObject



26
27
28
# File 'lib/cod/process.rb', line 26

def terminate
  @pipe.w.close
end

#waitObject



30
31
32
# File 'lib/cod/process.rb', line 30

def wait
  ::Process.wait(@pid)
end