I'm a new in the async world. Regarding your static method (from https://stackoverflow.com/a/25733275/1596974):
static async Task<TResult[]> WhenAll<TResult>(IEnumerable<Task<TResult>> tasks, TimeSpan timeout)
{
var timeoutTask = Task.Delay(timeout).ContinueWith(_ => default(TResult));
var completedTasks =
(await Task.WhenAll(tasks.Select(task => Task.WhenAny(task, timeoutTask)))).
Where(task => task != timeoutTask);
return await Task.WhenAll(completedTasks);
}
How should I use it in order to retrieve the results of those tasks? Just to be clear, what I need to achieve here is basically this:
- For each task I'm calling to several shipping providers in order to get the different shipping rates from them.
- Aggregate the response from all the shipping providers into a big list of shipping rates. Sometimes one (or more) of the shipping providers can be down. So, I need to retrieve the shipping rates from the tasks that completed successfully and just skip the ones that failed. I hope I was clear enough.