Class: Concur::EventMachineExecutor

Inherits:
Concur::Executor::Base show all
Defined in:
lib/executors/event_machine_executor.rb

Instance Method Summary collapse

Methods inherited from Concur::Executor::Base

#queue_size

Constructor Details

#initializeEventMachineExecutor

Returns a new instance of EventMachineExecutor.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/executors/event_machine_executor.rb', line 7

def initialize
  unless EventMachine.reactor_running? # also check EventMachine.reactor_thread? ??
    @in_thread = true
    @em_thread = Thread.new do
      EventMachine.run do
        puts 'Starting EventMachineExecutor...'
#          @futures.each do |f|
#
#          end
      end
      puts 'EventMachine loop done in executor thread'
    end
    sleep 0.1 # let EM startup
  else
    puts 'Reactor already running...'
    @in_thread = false
  end
end

Instance Method Details

#execute(runnable = nil, &blk) ⇒ Object



26
27
28
29
30
31
# File 'lib/executors/event_machine_executor.rb', line 26

def execute(runnable=nil, &blk)
  f = EventMachineFuture.new(runnable, &blk)
#      @futures = f
  EventMachine.schedule(f)
  f
end

#http_request(params, &blk) ⇒ Object

Abstracts the http client used that is suitable for the executor



42
43
44
# File 'lib/executors/event_machine_executor.rb', line 42

def http_request(params, &blk)
  f = EventMachineFuture2.new(params, &blk)
end

#shutdownObject



33
34
35
36
37
38
39
# File 'lib/executors/event_machine_executor.rb', line 33

def shutdown
  if @in_thread
    EventMachine.stop
    @em_thread.kill
  end
  puts 'shutdown'
end