Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vanquish the curse of transform async, but for List now #612

Merged
merged 1 commit into from
Jun 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/DynamicData/List/Internal/TransformAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ public IObservable<IChangeSet<TDestination>> Run()
observer =>
{
var state = new ChangeAwareList<TransformedItemContainer>();
var asyncLock = new SemaphoreSlim(1, 1);

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