SPARK-1634 - rx Cache() does not handle unsubscribe correctly.
This commit is contained in:
1 parent
23352438cf
commit
6ff71980aa
1 file changed
+20
-2
@@ -51,6 +51,7 @@ namespace bts.api.core {
|
||||
return $"added [{added}] changed [{changed}] removed [{removed}]";
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
public class Update<T, TKey> where TKey : IEquatable<TKey> {
|
||||
@@ -115,6 +116,15 @@ namespace bts.api.core {
|
||||
public IEnumerable<T> removed { get; }
|
||||
|
||||
public TKey key(T t) { return _key(t); }
|
||||
|
||||
#if DEBUG
|
||||
public override string ToString() {
|
||||
var a = string.Join(", ", added.Select(_key));
|
||||
var c = string.Join(", ", changed.Select(_key));
|
||||
var r = string.Join(", ", removed.Select(_key));
|
||||
return $"added [{a}] changed [{c}] removed [{r}]";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
struct RowEqualityComparer<T,TKey> : IEqualityComparer<T>, IEqualityComparer<(T,T)>
|
||||
@@ -235,6 +245,7 @@ namespace bts.api.core {
|
||||
object guard = new object();
|
||||
Update<T, TKey> cache = null;
|
||||
bool finished = false;
|
||||
Log.Api.info($"Naggle- {typeof(T).Name} Subscribed {observer.GetHashCode()}");
|
||||
|
||||
var d1 = source.Subscribe(update => {
|
||||
// subscribe to the source, merge updates (Quickbus thread)
|
||||
@@ -252,15 +263,20 @@ namespace bts.api.core {
|
||||
cache = null;
|
||||
}
|
||||
if (update != null) {
|
||||
Log.Api.diag($"Naggle- {update}");
|
||||
Log.Api.info($"Naggle- {typeof(T).Name} {update}");
|
||||
observer.OnNext(update);
|
||||
}
|
||||
if (finished) {
|
||||
Log.Api.info($"Naggle - Finished {typeof(T).Name} {observer.GetHashCode()}");
|
||||
observer.OnCompleted();
|
||||
}
|
||||
});
|
||||
|
||||
return new CompositeDisposable(d1, d2);
|
||||
return Disposable.Create(() => {
|
||||
Log.Api.info($"Naggle- Disposed {observer.GetHashCode()}");
|
||||
d1.Dispose();
|
||||
d2.Dispose();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -270,10 +286,12 @@ namespace bts.api.core {
|
||||
bool first = true;
|
||||
return inner.Subscribe(upd => {
|
||||
if (first) {
|
||||
Log.Api.info($"Cache- {typeof(T).Name} New");
|
||||
o.OnNext(upd.as_snapshot());
|
||||
first = false;
|
||||
}
|
||||
else {
|
||||
Log.Api.info($"cache- {typeof(T).Name} Update");
|
||||
o.OnNext(upd);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user