(no title)
weswilson | 2 years ago
ConcurrentDictionary<string, double> taxMap = new ConcurrentDictionary<string, double>();
await Task.WhenAll(migrantList
.SelectMany(m => m.StatesTraversed)
.Distinct()
.Select(async s => taxMap.TryAdd(s, await GetSalesAndUseTaxForStateAsync(s))));
migrantList.ForEach(mti => Console.WriteLine($"Total Relocation Fee: {mti.StatesTraversed.Sum(s => taxMap[s]) + mti.TotalMilesTravelled * .15}"));
This gets pretty close to negligible overhead. The above ran in 0.519s, including the .5s await time of the "API" call.I just wanted to show that there's an optimized solution that is also more concise in C#.
No comments yet.