Class: MultiProcessing::ExternalObject

Inherits:
BasicObject
Defined in:
lib/multiprocessing/externalobject.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ ExternalObject

Returns a new instance of ExternalObject.



7
8
9
10
11
12
13
# File 'lib/multiprocessing/externalobject.rb', line 7

def initialize obj
  @call_queue = Queue.new
  @result_queue = Queue.new
  @mutex = Mutex.new
  @closed = false
  @pid = fork{|obj| process_loop obj }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



47
48
49
# File 'lib/multiprocessing/externalobject.rb', line 47

def method_missing *args
  self.send *args
end

Instance Method Details

#closeObject



37
38
39
40
41
42
43
44
45
# File 'lib/multiprocessing/externalobject.rb', line 37

def close
  @mutex.synchronize do
    @closed = true
    begin
      Process.kill :TERM, @pid
    rescue
    end
  end
end

#send(name, *args) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/multiprocessing/externalobject.rb', line 29

def send name, *args
  @mutex.synchronize do
    raise ProcessError.new("already closed") if @closed
    @call_queue.enq [name, *args]
    return @result_queue.deq
  end
end