Skip to content

Commit

Permalink
Tweak single execution of blocks for BroadcastLogger to accurately ma…
Browse files Browse the repository at this point in the history
…intain existing semantics when only a single logger is present.
  • Loading branch information
armstrjare committed Sep 30, 2024
1 parent e5e9a38 commit 809cfbc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions activesupport/lib/active_support/broadcast_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,19 @@ def initialize_copy(other)

private
def dispatch(method, *args, **kwargs, &block)
yield.tap do |result|
block = proc { result }
end if block_given?
if block_given?
# Maintain semantics that the first logger yields the block
# as normal, but subsequent loggers won't re-execute the block.
# Instead, the initial result is immediately returned.
called, result = false, nil
block = proc { |*args, **kwargs|
if called then result
else
called = true
result = yield(*args, **kwargs)
end
}
end

@broadcasts.map { |logger|
if logger.respond_to?(method)
Expand Down

0 comments on commit 809cfbc

Please sign in to comment.