Skip to content

Commit

Permalink
Serialize TransformAsync using Concat (#639)
Browse files Browse the repository at this point in the history
Use Concat to ensure serialized sequence for List.TransformAsync
  • Loading branch information
RolandPheasant committed Sep 6, 2022
1 parent 17fe918 commit dfa5eef
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/DynamicData/List/Internal/TransformAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ private IObservable<IChangeSet<TDestination>> RunImpl()
var state = new ChangeAwareList<Transformer<TSource, TDestination>.TransformedItemContainer>();
var asyncLock = new SemaphoreSlim(1, 1);

return _source.Select(
async changes =>
{
try
{
await asyncLock.WaitAsync().ConfigureAwait(false);
await Transform(state, changes).ConfigureAwait(false);
return state;
}
finally
return _source.Select(async changes =>
{
asyncLock.Release();
}
}).Select(tasks => tasks.ToObservable()).SelectMany(items => items).Select(
transformed =>
try
{
await asyncLock.WaitAsync();
await Transform(state, changes);
return state;
}
finally
{
asyncLock.Release();
}
})
.Concat()
.Select(transformed =>
{
var changed = transformed.CaptureChanges();
return changed.Transform(container => container.Destination);
Expand Down

0 comments on commit dfa5eef

Please sign in to comment.