Skip to content

Commit

Permalink
Better use of Task.WhenAll
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunn committed Jan 7, 2025
1 parent 876e4e1 commit 20a2fd1
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions backend/LfClassicData/LfClassicMiniLcmApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,15 @@ private async IAsyncEnumerable<Entry> Query(QueryOptions? options = null, string

private async Task<Entry> ToEntry(Entities.Entry entry)
{
List<Sense> senses;
Sense[] senses;
if (entry.Senses is null)
{
senses = [];
}
else
{
var senseTasks = entry.Senses.OfType<Entities.Sense>().Select(sense => ToSense(entry.Guid, sense));
await Task.WhenAll(senseTasks);
senses = senseTasks.Select(task => task.Result).ToList();
senses = await Task.WhenAll(senseTasks);
}
return new Entry
{
Expand All @@ -257,7 +256,7 @@ private async Task<Entry> ToEntry(Entities.Entry entry)
LexemeForm = ToMultiString(entry.Lexeme),
Note = ToMultiString(entry.Note),
LiteralMeaning = ToMultiString(entry.LiteralMeaning),
Senses = senses,
Senses = new List<Sense>(senses),
};
}

Expand Down

0 comments on commit 20a2fd1

Please sign in to comment.