From 4054f13313f4047b2c73174aa73e57f1baba0840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Filip?= <34779382+tomasfil@users.noreply.github.com> Date: Sat, 25 Jun 2022 17:17:26 +0200 Subject: [PATCH] Vanquish the curse of transform async, but for List now (#612) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomáš Filip --- src/DynamicData/List/Internal/TransformAsync.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/DynamicData/List/Internal/TransformAsync.cs b/src/DynamicData/List/Internal/TransformAsync.cs index ab539f471..776b90a85 100644 --- a/src/DynamicData/List/Internal/TransformAsync.cs +++ b/src/DynamicData/List/Internal/TransformAsync.cs @@ -38,12 +38,21 @@ public IObservable> Run() observer => { var state = new ChangeAwareList(); + 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 => {