Async hive mind: Consider this
private static async Task A()
{
await DelayOneSecond();
await DelayOneSecond();
await DelayOneSecond();
}
private static async Task B()
{
await Task.WhenAll(DelayOneSecond(), DelayOneSecond(), DelayOneSecond());
}
private static Task DelayOneSecond() => Task.Delay(1000);
Which method will complete first? A, B or at the same time?
The code that runs them simultaneously is missing but imagine that bit is there.
My original answer was that await is a not a blocking operation and based on this similar answer here, these two are similar minus the difference that WhenAll propagates all exceptions at once making it easier not to lose exceptions and also WhenAll will not return immediately if one of the methods throw an exception.
However I was told later that the answer is B, B will complete first because it runs them in parallel. A will run them one after the other waiting for each one to complete before moving on to the next. I was also told: Await is non-blocking, it hands control back to the caller, the rest of the method is setup as a continuation so went execute until after the awaited call has completed.
I've been trying to find more info about this behaviour because I had assumed multiple awaits would work the same way. Can someone give more explanation on the answer