public async Task<List<T>> Execute<T>(IList<int> ids, Policy policy, Func<CancellationToken, int, Task<T>> mapperFunc, string logMessage) where T : class
{
var noDupsList = new HashSet<int>(ids).ToList();
var holder = new List<Task<T>>(noDupsList.Count);
var removeNull = new List<T>(noDupsList.Count);
using (var logMetric = new LogMetric(_logger, TITLE, "DatabaseCall"))
{
logMetric.Message = logMessage;
for (int i = 0; i < noDupsList.Count; i++)
{
var id = noDupsList[i];
holder.Add(ProcessData(policy, ct => mapperFunc(ct, id)));
}
var responses = await Task.WhenAll(holder);
for (int i = 0; i < responses.Length; i++)
{
var response = responses[i];
if (response != null)
{
removeNull.Add(response);
}
}
logMetric.StatusCode = (removeNull.Count == 0) ? 204 : 200;
}
return removeNull;
}
Became Hot Network Question