lib/ably/modules/message_emitter.rb in ably-0.8.10 vs lib/ably/modules/message_emitter.rb in ably-0.8.11
- old
+ new
@@ -2,10 +2,13 @@
module Ably::Modules
# Message emitter, subscriber and unsubscriber (Pub/Sub) functionality common to Channels and Presence
# In addition to standard Pub/Sub functionality, it allows subscribers to subscribe to :all.
module MessageEmitter
+
+ include Ably::Modules::SafeYield
+
# Subscribe to events on this object
#
# @param names [String,Symbol] Optional, the event name(s) to subscribe to. Defaults to `:all` events
# @yield [Object] For each event, the provided block is called with the event payload object
#
@@ -48,11 +51,11 @@
#
# @return [void]
#
# @api private
def emit_message(name, payload)
- message_emitter_subscriptions[:all].each { |cb| cb.call(payload) }
- message_emitter_subscriptions[name].each { |cb| cb.call(payload) } if name
+ message_emitter_subscriptions[:all].each { |cb| safe_yield(cb, payload) }
+ message_emitter_subscriptions[name].each { |cb| safe_yield(cb, payload) } if name
end
private
def message_emitter_subscriptions
@message_emitter_subscriptions ||= Hash.new { |hash, key| hash[key] = [] }