Module: EventMachine::Ventually::Emify

Defined in:
lib/em-ventually/emify.rb

Instance Method Summary collapse

Instance Method Details

#_emObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/em-ventually/emify.rb', line 4

def _em
  result = nil
  if EM.reactor_running?
    result = yield
  else
    EM.run do
      begin
        result = yield
      ensure
        unless instance_variable_defined?(:@_manually_stop_em) && @_manually_stop_em
          EM.stop if (!instance_variable_defined?(:@_pool) || @_pool.nil? || @_pool.empty?) && EM.reactor_running?
        end
      end
    end
  end
  result
end