fix: Use AtomicGate to make TableUpdate Select ext thread-safe

This commit is contained in:
John Colvin committed 2026-01-04 21:19:00 +00:00
1 parent 549529aa60
commit 9ebc282ba5
1 file changed
+3
@@ -3,6 +3,7 @@ namespace bts.api.core {
using Spark.Api;
using Spark.Core.Reactive;
using Spark.Core.Threading;
using System;
using System.Collections.Generic;
@@ -617,8 +618,10 @@ namespace bts.api.core {
public static IObservable<TableUpdate<T2, TKey>>
Select<T1, T2, TKey>(this IObservable<TableUpdate<T1, TKey>> src, Func<T1, T2> map, Func<T2, TKey> key) where TKey : IEquatable<TKey> =>
Observable.Create<TableUpdate<T2, TKey>>(observer => {
var gate = new AtomicGate();
var cache = ImmutableDictionary<TKey, T2>.Empty;
return src.Subscribe(update => {
using var _ = gate.BeginTransaction();
var added = update.AddedItems.Select(map);
var removed = update.RemovedItems.Select(map);
var changes = update.Changes.Select(ch => new Change<T2>(map(ch.Old), map(ch.New)));