Skip to content
Browse files

don't try and unsubscribe an observer twice

  • Loading branch information...
1 parent 806e820 commit a92c3e8600bf2535d1c42ebee5335dc663c329fe @cloudshift committed
Showing with 19 additions and 11 deletions.
  1. +19 −11 cloudshift/core/ObservableImpl.hx
View
30 cloudshift/core/ObservableImpl.hx
@@ -20,6 +20,7 @@ class ObservableImpl<T> implements Observable<T> {
public function
notify(v:T) {
+
#if debug
if (v == null) {
throw "huh? can't notify null object";
@@ -49,20 +50,27 @@ class ObservableImpl<T> implements Observable<T> {
_event.notify(Add(info));
return function() {
- h.handler = null;
- _unsubscribes++;
- if (_unsubscribes >= CLEANUP) {
- trace("cleaning up");
- _unsubscribes = 0;
- _observers = _observers.filter(function(s) {
- return s.handler != null;
- });
+ if (h.handler != null) { // check we don't call this twice
+ h.handler = null;
+ _unsubscribes++;
+ if (_unsubscribes >= CLEANUP) {
+ cleanup();
+ }
+ if (_event != null)
+ _event.notify(Del(info));
}
-
- if (_event != null)
- _event.notify(Del(info));
}
}
+
+ function cleanup() {
+ trace("cleaning up");
+ _unsubscribes = 0;
+ _observers = _observers.filter(function(s) {
+ if (s.handler == null)
+ trace("filtering "+s.info);
+ return s.handler != null;
+ });
+ }
public function
peers():Array<Dynamic> {

0 comments on commit a92c3e8

Please sign in to comment.
Something went wrong with that request. Please try again.