Class: Pthread::PthreadExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/pthread/pthread_executor.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, queue = nil) ⇒ PthreadExecutor

Returns a new instance of PthreadExecutor.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pthread/pthread_executor.rb', line 4

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