-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
on('attached') registration in an on('attached') block fires immediately #364
Comments
Should the ordering of event registrations / emitting be part of the 0.10 spec perhaps? |
This is because it's appending to an array while iterating through it. Fix would be for emit() to copy the listeners arrays before it starts. I'd be fine with a spec item to enforce that if you think it's necessary. |
Yup, see https://github.com/ably/ably-ruby/blob/master/lib/ably/modules/event_emitter.rb#L82 and https://github.com/ably/ably-ruby/blob/master/spec/unit/modules/event_emitter_spec.rb#L73-L101, I clone it before iterating over and emitting. I personally think this should be part of the spec, but open to feedback |
The spec should say that every listener that is registered at the time of the call should called exactly once. It shouldn't say anything about cloning arrays of listeners. Other languages have other ways of meeting that requirement. |
So that listeners added in listener callbacks aren't called in that emit() call Fixes #364
Fixed in 0.9 by a2fb1e2 (Not planning to fix in 0.8 as it is arguably a breaking api change; let me know if you disagree) |
Well, I think only in the same way that any bugfix is potentially a breaking change for somebody. |
This isn't like a crash or a race condition; the previous behaviour was stable and predictable, so isn't it plausible that someone have built an app that relies on it (albeit probably unintentionally)? |
I'm say that people can come to depend on all sorts of out-of-spec behaviours, but that shouldn't stop us fixing them, in general. In this case I think the adverse impact of leaving it is small, and the likelihood we break someone's code by fixing it is smaller still. |
So that listeners added in listener callbacks aren't called in that emit() call Fixes #364
FYI, PR for this now at ably/docs#240 |
Easier to show in code
Both of these result in the following, even though there is only one attach:
I don't think it's valid that an event handler, registered in the listener for an event should fire immediately. I think it's pretty clear that the developer wants that to happen the next time that event happens, not this time.
However, this does work as expected:
The text was updated successfully, but these errors were encountered: