Observable API and listeners fixups #593
Merged
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.
This makes the
ObservableMixin
less fragile for use as a mix-in by eliminating its parameter-taking__init__
method, and some cleanups and docstrings. It also adds an (optional!) list of "valid events" to make users of.on()
(or even internal uses of.fire()
) complain if you mis-type an event name.The other commit tackles the LTS listener API by fixing how they're fired/invoked. Doing the invokes in e.g.
onJoin
won't work with most of the code out there (including all the examples) because the API contract never specified to callsuper()
(and basically no code does this). This means that the 'join' event is basically never fired properly.So, as per LTS API discussions there are 5 events. Note that I made one subtle change that makes a big difference (to when 'join' fires):
Above "completed" means the method has run, and any future/deferred returned has also completed. The reason I made 'join' fire before onJoin has run and completed is, consider code like:
That is, things that use
onJoin
as essentially a "main" function -- do all their work, and then disconnect the session. In the above, if we wait foronJoin
to complete before we fire the 'join' listeners, then we very counter-intuitively would fire 'leave' before firing 'join'.So, now 'join' fires as soon as we get the Hello message, and then the previously-discussed 'ready' fires after onJoin has completed (and all 'join' listeners have completed). Also, this is implemented such that it doesn't matter which of the over-ridable methods in ApplicationSession you choose to override, and doesn't care if you call
super()
or not. Also, any errors from listeners are logged (but ignored).