提交 a67fdc02 编写于 作者: G Guo Xiang Tan

Update documentation to reflect unsubscription with name.

上级 02ee081c
...@@ -141,6 +141,11 @@ module ActiveSupport ...@@ -141,6 +141,11 @@ module ActiveSupport
# #
# ActiveSupport::Notifications.unsubscribe(subscriber) # ActiveSupport::Notifications.unsubscribe(subscriber)
# #
# You can also unsubscribe by passing the name of the subscriber object. Note
# that this will unsubscribe all subscriptions with the given name:
#
# ActiveSupport::Notifications.unsubscribe("render")
#
# == Default Queue # == Default Queue
# #
# Notifications ships with a queue implementation that consumes and publishes events # Notifications ships with a queue implementation that consumes and publishes events
...@@ -173,8 +178,8 @@ def subscribed(callback, *args, &block) ...@@ -173,8 +178,8 @@ def subscribed(callback, *args, &block)
unsubscribe(subscriber) unsubscribe(subscriber)
end end
def unsubscribe(args) def unsubscribe(subscriber_or_name)
notifier.unsubscribe(args) notifier.unsubscribe(subscriber_or_name)
end end
def instrumenter def instrumenter
......
...@@ -25,9 +25,9 @@ def subscribe(pattern = nil, block = Proc.new) ...@@ -25,9 +25,9 @@ def subscribe(pattern = nil, block = Proc.new)
subscriber subscriber
end end
def unsubscribe(subscriber) def unsubscribe(subscriber_or_name)
synchronize do synchronize do
@subscribers.reject! { |s| s.matches?(subscriber) } @subscribers.reject! { |s| s.matches?(subscriber_or_name) }
@listeners_for.clear @listeners_for.clear
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册