refactor: Ensure stream subscriptions only disposed once

In the debugger, I noticed a few streams were unhooking their internal
onChange callbacks unnecessarily (when they were already unhooked).
This commit is contained in:
John Colvin committed 2026-01-10 12:59:14 -05:00
1 parent 849c6c28e5
commit 9de4b27003
4 files changed
+74 -35

No files matched your search

@@ -102,8 +102,11 @@ namespace BCG
myRealSource.onChange -= currValue;
else
{
myOnChangeDelegate =
(ChangeDelegate) Delegate.Remove (myOnChangeDelegate,currValue);
if (myOnChangeDelegate is null) {
Log.DataFlow.warn("Attempted to remove DataStream callback called when change delegate already null");
} else {
myOnChangeDelegate = (ChangeDelegate)Delegate.Remove(myOnChangeDelegate, currValue);
}
// this is need to avoid a callback in a reentrant add.
if (myPendingAdds.Count > 0)
@@ -0,0 +1,23 @@
#nullable enable
namespace Bts.DataStreamCore;
using BCG;
using mbts.utils;
using Spark.Core.Disposables;
using System;
public static class ViewStreamExtensions {
public static IDisposable Subscribe(this ViewStream viewStream, Action<IDataPacket> onData) {
viewStream.onChange += OnChange;
return Disposable.Create(Unsubscribe);
void OnChange(object? obj) =>
onData(ExceptionAssert.Argument.Is<IDataPacket>(obj));
void Unsubscribe() =>
viewStream.onChange -= OnChange;
}
}