1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove instrument! and require thread from AS::Notifications.

This commit is contained in:
José Valim 2010-02-04 10:39:55 +01:00
parent efa850558f
commit 31248fe369
4 changed files with 3 additions and 30 deletions

View file

@ -45,7 +45,7 @@ module ActiveSupport
class << self
attr_writer :notifier
delegate :publish, :subscribe, :to => :notifier
delegate :instrument, :instrument!, :to => :instrumenter
delegate :instrument, :to => :instrumenter
def notifier
@notifier ||= Notifier.new

View file

@ -1,5 +1,3 @@
require 'thread'
module ActiveSupport
module Notifications
# This is a default queue implementation that ships with Notifications. It
@ -21,8 +19,8 @@ module ActiveSupport
@subscribers.each { |s| s.publish(*args) }
end
# This is a sync queue, so there is not waiting.
def wait
sleep(0.05) until @subscribers.all?(&:drained?)
end
# Used for internal implementation only.

View file

@ -20,15 +20,6 @@ module ActiveSupport
result
end
# The same as instrument, but sends the notification even if the yielded
# block raises an error.
def instrument!(name, payload={})
time = Time.now
yield(payload) if block_given?
ensure
@notifier.publish(name, time, Time.now, @id, payload)
end
private
def unique_id
SecureRandom.hex(10)

View file

@ -67,29 +67,13 @@ module Notifications
end
class InstrumentationTest < TestCase
delegate :instrument, :instrument!, :to => ActiveSupport::Notifications
delegate :instrument, :to => ActiveSupport::Notifications
def test_instrument_returns_block_result
assert_equal 2, instrument(:awesome) { 1 + 1 }
drain
end
def test_instrument_with_bang_returns_result_even_on_failure
begin
instrument!(:awesome, :payload => "notifications") do
raise "FAIL"
end
flunk
rescue
end
drain
assert_equal 1, @events.size
assert_equal :awesome, @events.last.name
assert_equal Hash[:payload => "notifications"], @events.last.payload
end
def test_instrument_yields_the_paylod_for_further_modification
assert_equal 2, instrument(:awesome) { |p| p[:result] = 1 + 1 }
drain