Repository navigation
Conversation
ListenersPriorityQueue::getIterator() returns an ArrayIterator over the listeners collected when dispatch() starts. A listener removed during dispatch therefore still runs, and one added during dispatch does not. Document this and cover it with a test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
CI fails in "Install PHP dependencies" before any check runs, independent of this change: |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Dispatcher::dispatch()iterates overListenersPriorityQueue::getIterator(), which returns anArrayIteratorover a snapshot of the listeners. If a higher-priority listener removes a later listener, the removed listener still runs for the current event; a listener added during dispatch is skipped until the next dispatch. This is reasonable, but nowhere documented.This PR documents the current semantics and adds a test that pins them down. No code changes.
The alternative would be to check
has()before invoking each listener, so that listeners removed during dispatch are skipped. That changes behaviour (and costs a lookup per listener), so it is not done here.Testing Instructions
DispatcherTest::testDispatchUsesTheListenersRegisteredWhenItStarted()registers a high-priority listener that removes the second listener and adds a third one during dispatch, and asserts that the second listener still ran, the third did not, and that the registrations were changed nonetheless.Run
vendor/bin/phpunit.Documentation Changes Required
docs/overview.md, "Things to know before you build on this": new entry "dispatch()works on a snapshot of the listeners".🤖 Generated with Claude Code