You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to subscribe to events during a call to NotificationCenter.publish(), you get a ConcurrentModificationException from the subscribers list.
One solution would be to make a copy of the subscribers list before publishing. Here's a minimal test case (tested with mvvmFx 1.3.1):
importorg.junit.Test;
importde.saxsys.mvvmfx.utils.notifications.NotificationCenter;
importde.saxsys.mvvmfx.utils.notifications.NotificationCenterFactory;
publicclassNotificationCenterTest {
@TestpublicvoidshouldAllowSubscribeDuringPublish() throwsException {
NotificationCenterc = NotificationCenterFactory.getNotificationCenter();
/* Minimal example (triggers a ConcurrentModificationException in NotificationCenter */c.subscribe("MSG", (key1, payload1) -> {
c.subscribe("MSG", (key2, payload2) -> {
System.out.println("I want to subscribe during a publish()");
});
});
c.publish("MSG");
/* * Real use case: * * ParentView * | | * ChildView1 ChildView2 * * * ChildView1 publishes a global event that causes ParentView * to create a new instance of ChildView2. * ChildView2 tries to subscribe to another global event in its initialize() method. * * Because NotificationCenter.publish() does not make a copy before publishing * events, we get a ConcurrentModificationException. */
}
}
The text was updated successfully, but these errors were encountered:
When trying to subscribe to events during a call to NotificationCenter.publish(), you get a ConcurrentModificationException from the subscribers list.
One solution would be to make a copy of the subscribers list before publishing. Here's a minimal test case (tested with mvvmFx 1.3.1):
The text was updated successfully, but these errors were encountered: