forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure ActiveSupport::BroadcastLogger only executes blocks once.
Prior to this change, BroadcastLoggers would iterate each broadcast and execute the user provided block for each. This resulted in unintended behaviour since a user-provided block could execute multiple times. The consumer of any Logger would reasonably expect than when calling a method with a block, that block would only execute a single time. That is, the fact that a Logger is a BroadcastLogger should be irrelevant to user. The most significant example of this is with ActiveSupport::TaggedLogging. If a BroadcastLogger is used, and there are multiple loggers being broadcast to that respond to the `tagged` method, then calling `tagged` with a block would result in the block being called multiple times. For example: ```ruby broadcasts = ActiveSupport::BroadcastLogger.new( *Array.new(2) { ActiveSupport::TaggedLogging.logger } ) number = 0 broadcasts.tagged("FOO") { broadcasts.log(++number.to_s) } ``` This commit modifies the implementation used for dispatching to instead 'nest' methods called with a block such that the user-provided block is only executed in the innermost call. For example, the above example would effectively be performed as so: ```ruby broadcasts[0].tagged("FOO") { broadcasts[1].tagged("FOO") { yield } } ```
- Loading branch information
1 parent
13d5f87
commit 6b14642
Showing
2 changed files
with
60 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters