Skip to content
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

Fixed notification loop in View.notifyObservers for cases if some Observers has been removed during the notification loop. #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

alphashooter
Copy link

No description provided.

bluntcoder and others added 3 commits July 22, 2013 14:50
@alphashooter
Copy link
Author

notifyObservers() method may fail if any Observer to be notified next is removed during the notification loop. E.g. if you register two Mediators for the same notification and the first one removes the second during notification handling, the second Mediator will be notified anyway, and moreover notified after onRemove() method called.
Iterating through a copy of observers_ ref prevents array shifting if you remove any Observer which is already notified (commit 107233d2c23e44a2be96f4fefa4affc74f3afde5); but no checks has been added for the case if you remove any Observer to be notified next. For this case observers_ref holds reference to the source array of Observers; so if any Observer is removed, observers_ref.indexOf(observer) has result -1 and loop continues to the next iteration.

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.

3 participants