From 378464a2e47bb849f3351cb8c87366554b7ce74d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 21 Jan 2010 13:05:30 +0100 Subject: Default to sync instrumentation. --- .../lib/active_support/notifications/fanout.rb | 36 ++-------------------- activesupport/test/notifications_test.rb | 18 +---------- 2 files changed, 4 insertions(+), 50 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index bb07e4765c..ac482a2ec8 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -3,11 +3,9 @@ require 'thread' module ActiveSupport module Notifications # This is a default queue implementation that ships with Notifications. It - # consumes events in a thread and publish them to all registered subscribers. - # + # just pushes events to all registered subscribers. class Fanout - def initialize(sync = false) - @subscriber_klass = sync ? Subscriber : AsyncSubscriber + def initialize @subscribers = [] end @@ -16,7 +14,7 @@ module ActiveSupport end def subscribe(pattern = nil, &block) - @subscribers << @subscriber_klass.new(pattern, &block) + @subscribers << Subscriber.new(pattern, &block) end def publish(*args) @@ -68,34 +66,6 @@ module ActiveSupport @block.call(*args) end end - - # Used for internal implementation only. - class AsyncSubscriber < Subscriber #:nodoc: - def initialize(pattern, &block) - super - @events = Queue.new - start_consumer - end - - def drained? - @events.empty? - end - - private - def start_consumer - Thread.new { consume } - end - - def consume - while args = @events.shift - @block.call(*args) - end - end - - def push(*args) - @events << args - end - end end end end diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index c41d81fe7e..d3af535c26 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -3,18 +3,12 @@ require 'abstract_unit' module Notifications class TestCase < ActiveSupport::TestCase def setup - Thread.abort_on_exception = true - ActiveSupport::Notifications.notifier = nil @notifier = ActiveSupport::Notifications.notifier @events = [] @notifier.subscribe { |*args| @events << event(*args) } end - def teardown - Thread.abort_on_exception = false - end - private def event(*args) ActiveSupport::Notifications::Event.new(*args) @@ -25,7 +19,7 @@ module Notifications end end - class PubSubTest < TestCase + class SyncPubSubTest < TestCase def test_events_are_published_to_a_listener @notifier.publish :foo @notifier.wait @@ -72,16 +66,6 @@ module Notifications end end - class SyncPubSubTest < PubSubTest - def setup - Thread.abort_on_exception = true - - @notifier = ActiveSupport::Notifications::Notifier.new(ActiveSupport::Notifications::Fanout.new(true)) - @events = [] - @notifier.subscribe { |*args| @events << event(*args) } - end - end - class InstrumentationTest < TestCase delegate :instrument, :instrument!, :to => ActiveSupport::Notifications -- cgit v1.2.3