Method: Pthread::PthreadExecutor#initialize

Defined in:
lib/pthread/pthread_executor.rb

#initialize(host, queue = nil) ⇒ PthreadExecutor

Initliazes new executor.

Examples:

Connect to remote dRb service

Pthread::PthreadExecutor.new '192.168.1.100:12345', :tasks

Parameters:

  • host (String)

    DRB host that has main programm running.

  • queue (String, Symbol) (defaults to: nil)

    optinal queue name to attach executor.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pthread/pthread_executor.rb', line 16

def initialize(host, queue=nil)
  DRb.start_service
  ts = DRbObject.new_with_uri("druby://#{host}")

  loop do
    pthread_id, _, code, context = ts.take([nil, queue, nil, nil])

    context && context.each do |a, v|
      singleton_class.class_eval { attr_accessor a }
      self.send("#{a}=", context[a])
    end

    value = begin
      eval(code)
    rescue => e
      e
    end

    ts.write([pthread_id, value])
  end
rescue DRb::DRbConnError
  exit 0
end