Skip to content

[4.x] Document that dispatch() works on a snapshot of the listeners - #56

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-document-dispatch-snapshot
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-document-dispatch-snapshot

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Dispatcher::dispatch() iterates over ListenersPriorityQueue::getIterator(), which returns an ArrayIterator over 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

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>
@Hackwar

Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

CI fails in "Install PHP dependencies" before any check runs, independent of this change: joomla/console (require-dev) requires joomla/event ^4.0, but the checked-out root package gets a dev-<branch|sha> version that does not satisfy it ("joomla/event dev-… is the root package and cannot be modified"). The scheduled runs on 4.x-dev fail the same way (every run since at least 2026-08-31). Locally, with COMPOSER_ROOT_VERSION=4.0.x-dev, phpunit, phpcs (src) and phpstan pass. Fixing it needs a root version in CI (e.g. COMPOSER_ROOT_VERSION in the shared workflow, or a branch-alias plus enough git history for Composer to guess the version), which is outside the scope of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant