Module: EventMachine

Defined in:
lib/lspace/eventmachine.rb

Overview

Optional module to make EventMachine preserve LSpaces in its event callbacks. Not loaded by default; you must require ‘lspace/eventmachine’ to use it.

Defined Under Namespace

Modules: Deferrable, LSpacePreserver Classes: Connection

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(*args, &block) ⇒ Object

Override run to ensure that the LSpace context is re-entered more appropriately.

This ensures that all blocks scheduled on the eventmachine reactor will be wrapped in the around_filters you define, and makes implementing things like a global error handler, or em-monitor a little easier.



46
47
48
49
50
51
52
53
54
55
# File 'lib/lspace/eventmachine.rb', line 46

def run(*args, &block)
  lspace = LSpace.current
  LSpace.clean do
    run_in_current_lspace(*args) do |*a, &b|
      lspace.enter do
        block.call *a, &b if block_given?
      end
    end
  end
end

.run_in_current_lspaceObject

By default EM::run will temporarily switch to a clean LSpace to ensure that all your around_filters are run for every block executed on the reactor.

If you don’t want this behaviour, you can call EM.run_in_current_lspace which will continue using the current lspace.



38
# File 'lib/lspace/eventmachine.rb', line 38

alias_method :run_in_current_lspace, :run

.start_server(*args, &block) ⇒ Object



17
18
19
20
21
# File 'lib/lspace/eventmachine.rb', line 17

def start_server(*args, &block)
  s = start_server_without_lspace(*args, &(block ? block.in_lspace : nil))
  @acceptors[s][0].in_lspace
  s
end

.start_server_without_lspaceObject



16
# File 'lib/lspace/eventmachine.rb', line 16

alias_method :start_server_without_lspace, :start_server

Instance Method Details

#attach_server(*args, &block) ⇒ Object



25
26
27
28
29
# File 'lib/lspace/eventmachine.rb', line 25

def attach_server(*args, &block)
  s = attach_server_without_lspace(*args, &(block ? block.in_lspace : nil))
  @acceptors[s][0].in_lspace
  s
end

#attach_server_without_lspaceObject



24
# File 'lib/lspace/eventmachine.rb', line 24

alias_method :attach_server_without_lspace, :attach_server