Create new EventDispatcher to move user-provided callback execution out of the main thread - #403
Open
ppicom wants to merge 7 commits into
Open
Conversation
ppicom
force-pushed
the
fix/eg-4649-move-event-callback-execution-out-of-the-hot-path-of
branch
from
August 4, 2026 15:14
54c3b78 to
fa3f132
Compare
Coverage Report for CI Build 30923141826Coverage increased (+0.3%) to 93.678%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
馃挍 - Coveralls |
we'll cross that bridge when we get to that river
I feel like this is self explanatory, happy to reconsider, though.
ppicom
commented
Aug 5, 2026
| return self._parsed_payload | ||
|
|
||
|
|
||
| _SHUTDOWN = object() |
Contributor
Author
There was a problem hiding this comment.
On second thought, this sentinel is not super very idiomatic.
Contributor
Author
There was a problem hiding this comment.
Replaced by a class-based one.
Using an instance of object was a bit awkward
ppicom
marked this pull request as ready for review
August 5, 2026 12:40
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
The pull request introduces the implementation of
EventDispatcher. Its goal is to move all event-and-callback-related code to the same file. At the same time, theEventDispatcheris based on threads: the "callers" of the dispatcher will useemit_eventto queue an event, and a worker thread managed by the dispatcher will drain the queue.In this pull request, the Dispatcher is not yet wired to anyone.
Reason for these changes
This is the initial step towards solving two problems:
is_enabledindefinitely; andUnleashClient(i.e.AsyncUnleashClient) will also support sending events to a callbackBy introducing a single class that deals with event-sending as a whole, code will be shared and we ensure we don't run it in the hot path anymore (as long as we publish events through the
EventDispatcher).Tricky parts when reviewing
Threads and locks
EventDispatcherdeals with locks and threads, which is always fun. Variables like_closed, as well as the two centinels (_SHUTDOWNand_FlushMarker) help manage the synchronization of operations:close()Backpressure
I discarded the option of adding a timeout or a number of retries to a user's callback. I'm happy to revisit the decision.