Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Evented notifications should take priority over Timed #7338

Merged
merged 1 commit into from

3 participants

@sax

In cases where a notification subscriber includes methods to support
both Evented and Timed events, Evented should take priority over Timed.
This allows subscribers to be backwards compatible (older Rails only
allows Timed events) while defaulting to newer behavior.

@sax sax Evented notifications take priority over Timed notifications
In cases where a notification subscriber includes methods to support
both Evented and Timed events, Evented should take priority over Timed.
This allows subscribers to be backwards compatible (older Rails only
allows Timed events) while defaulting to newer behavior.
6fe36ba
@tenderlove tenderlove merged commit 1ce6409 into rails:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 12, 2012
  1. @sax

    Evented notifications take priority over Timed notifications

    sax authored
    In cases where a notification subscriber includes methods to support
    both Evented and Timed events, Evented should take priority over Timed.
    This allows subscribers to be backwards compatible (older Rails only
    allows Timed events) while defaulting to newer behavior.
This page is out of date. Refresh to see the latest.
View
6 activesupport/lib/active_support/notifications/fanout.rb
@@ -59,10 +59,10 @@ def wait
module Subscribers # :nodoc:
def self.new(pattern, listener)
- if listener.respond_to?(:call)
- subscriber = Timed.new pattern, listener
- else
+ if listener.respond_to?(:start) and listener.respond_to?(:finish)
subscriber = Evented.new pattern, listener
+ else
+ subscriber = Timed.new pattern, listener
end
unless pattern
View
20 activesupport/test/notifications/evented_notification_test.rb
@@ -19,6 +19,12 @@ def finish(name, id, payload)
end
end
+ class ListenerWithTimedSupport < Listener
+ def call(name, start, finish, id, payload)
+ @events << [:call, name, start, finish, id, payload]
+ end
+ end
+
def test_evented_listener
notifier = Fanout.new
listener = Listener.new
@@ -62,6 +68,20 @@ def test_listen_to_everything
[:finish, 'hello', 1, {}],
], listener.events
end
+
+ def test_evented_listener_priority
+ notifier = Fanout.new
+ listener = ListenerWithTimedSupport.new
+ notifier.subscribe 'hi', listener
+
+ notifier.start 'hi', 1, {}
+ notifier.finish 'hi', 1, {}
+
+ assert_equal [
+ [:start, 'hi', 1, {}],
+ [:finish, 'hi', 1, {}]
+ ], listener.events
+ end
end
end
end
Something went wrong with that request. Please try again.