Class: Wisper::ObjectRegistration

Inherits:
Object
  • Object
show all
Defined in:
lib/wisper/async.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listener, options) ⇒ ObjectRegistration

Returns a new instance of ObjectRegistration.



12
13
14
15
# File 'lib/wisper/async.rb', line 12

def initialize(listener, options)
  @async = options.delete(:async) { false }
  old_initialize(listener, options)
end

Instance Attribute Details

#asyncObject (readonly)

Returns the value of attribute async.



8
9
10
# File 'lib/wisper/async.rb', line 8

def async
  @async
end

Instance Method Details

#broadcast(event, publisher, *args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/wisper/async.rb', line 17

def broadcast(event, publisher, *args)
  method_to_call = map_event_to_method(event)
  if should_broadcast?(event) && listener.respond_to?(method_to_call)
    unless async
      listener.public_send(method_to_call, *args)
    else
      Async::Listener.new(listener, method_to_call).async.public_send(method_to_call, *args)
    end
  end
end

#old_initializeObject



10
# File 'lib/wisper/async.rb', line 10

alias_method :old_initialize, :initialize