diff options
Diffstat (limited to 'activesupport/lib/active_support/notifications')
-rw-r--r-- | activesupport/lib/active_support/notifications/fanout.rb | 11 | ||||
-rw-r--r-- | activesupport/lib/active_support/notifications/instrumenter.rb | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 64f315cb6a..adc34f3286 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -9,15 +9,16 @@ module ActiveSupport end def subscribe(pattern = nil, block = Proc.new) - @listeners_for.clear - Subscriber.new(pattern, block).tap do |s| + subscriber = Subscriber.new(pattern, block).tap do |s| @subscribers << s end + @listeners_for.clear + subscriber end def unsubscribe(subscriber) - @listeners_for.clear @subscribers.reject! {|s| s.matches?(subscriber)} + @listeners_for.clear end def publish(name, *args) @@ -28,6 +29,10 @@ module ActiveSupport @listeners_for[name] ||= @subscribers.select { |s| s.subscribed_to?(name) } end + def listening?(name) + listeners_for(name).any? + end + # This is a sync queue, so there is not waiting. def wait end diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index e98189f899..713d5a5f25 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -19,7 +19,7 @@ module ActiveSupport def instrument(name, payload={}) begin @started = Time.now - yield(payload) if block_given? + yield rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e |