From bea2c3135d9f9a678fc729999b11f5c69081e3e9 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Tue, 14 Jan 2025 13:05:21 +0700 Subject: [PATCH] avoid calling wait on a task --- backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs b/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs index 7a5412991..50c516dd2 100644 --- a/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs +++ b/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs @@ -323,14 +323,15 @@ public async Task BulkCreateEntries(IAsyncEnumerable entries) var semanticDomains = await SemanticDomains.ToDictionaryAsync(sd => sd.Id, sd => sd); var partsOfSpeech = await PartsOfSpeech.ToDictionaryAsync(p => p.Id, p => p); await dataModel.AddChanges(ClientId, - entries.ToBlockingEnumerable() - .SelectMany(entry => + await entries.SelectAwait(async entry => { - validators.ValidateAndThrow(entry).Wait(); //? - return CreateEntryChanges(entry, semanticDomains, partsOfSpeech); + await validators.ValidateAndThrow(entry); + return entry; }) + .SelectMany(entry => CreateEntryChanges(entry, semanticDomains, partsOfSpeech).ToAsyncEnumerable()) //force entries to be created first, this avoids issues where references are created before the entry is created .OrderBy(c => c is CreateEntryChange ? 0 : 1) + .ToArrayAsync() ); }