Skip to content

Commit

Permalink
unregister MessageLongPollObserver after taking notice and emitting n…
Browse files Browse the repository at this point in the history
…otifications!
  • Loading branch information
svencc committed Oct 20, 2023
1 parent a1c2332 commit c75c3b1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/com/recom/observer/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public void observationStoppedThrough(final @NonNull Observing<T> observer) {

@Override
public void notifyObserversWith(@NonNull final Notification<T> notification) {
observersWatchingMe.forEach(observer -> observer.takeNotice(this, notification));
// run through a copy of the list to avoid ConcurrentModificationException when removing observers!
final List<Observing<T>> copiedObserversWatchingMe = new ArrayList<>(observersWatchingMe);
copiedObserversWatchingMe.forEach(observer -> observer.takeNotice(this, notification));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void takeNotice(
responseBodyEmitter.completeWithError(e);
} finally {
responseBodyEmitter.complete();
subject.observationStoppedThrough(this);
}
}

Expand Down

0 comments on commit c75c3b1

Please sign in to comment.