aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-03-01 16:01:08 -0800
committerCarlhuda <carlhuda@engineyard.com>2010-03-01 17:45:37 -0800
commitc88360ef3651702ca8f7f600e15774f51c84698b (patch)
tree2582399b60fac70eba83ea3988a82c72c98e53f3 /activesupport/lib/active_support
parent048b436f33059f1da7659edf9ca05fb46042b253 (diff)
downloadrails-c88360ef3651702ca8f7f600e15774f51c84698b.tar.gz
rails-c88360ef3651702ca8f7f600e15774f51c84698b.tar.bz2
rails-c88360ef3651702ca8f7f600e15774f51c84698b.zip
You can unsubscribe a subscriber
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/notifications.rb4
-rw-r--r--activesupport/lib/active_support/notifications/fanout.rb11
2 files changed, 12 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb
index 06d57765bc..fca2efd969 100644
--- a/activesupport/lib/active_support/notifications.rb
+++ b/activesupport/lib/active_support/notifications.rb
@@ -69,6 +69,10 @@ module ActiveSupport
@queue.bind(pattern).subscribe(&block)
end
+ def unsubscribe(subscriber)
+ @queue.unsubscribe(subscriber)
+ end
+
def wait
@queue.wait
end
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb
index 090eb1eac6..e08011e23f 100644
--- a/activesupport/lib/active_support/notifications/fanout.rb
+++ b/activesupport/lib/active_support/notifications/fanout.rb
@@ -4,7 +4,7 @@ module ActiveSupport
# just pushes events to all registered log subscribers.
class Fanout
def initialize
- @log_subscribers = []
+ @subscribers = []
end
def bind(pattern)
@@ -12,11 +12,16 @@ module ActiveSupport
end
def subscribe(pattern = nil, &block)
- @log_subscribers << Subscriber.new(pattern, &block)
+ @subscribers << Subscriber.new(pattern, &block)
+ @subscribers.last
+ end
+
+ def unsubscribe(subscriber)
+ @subscribers.delete(subscriber)
end
def publish(*args)
- @log_subscribers.each { |s| s.publish(*args) }
+ @subscribers.each { |s| s.publish(*args) }
end
# This is a sync queue, so there is not waiting.