title: Sequential version of Task.WhenAll
body: <p>Is there a nonblocking <code>Task.WaitAll</code> similar to <code>Task.WhenAll</code>, but not parallel?</p>
  <p>I wrote this, but maybe it’s built-in?</p>
  <pre><code>public async Task&lt;IEnumerable&lt;T&gt;&gt; AwaitAllAsync&lt;T&gt;(IEnumerable&lt;Task&lt;T&gt;&gt; tasks)
  {
      List&lt;T&gt; result = new List&lt;T&gt;();
      foreach(var task in tasks)
      {
          result.Add(await task);
      }
  
      return result;
  }
  </code></pre>
  <p>I want to know if there is a built-in way of waiting for all tasks to complete in async, but a sequential way.</p>
  <p>Consider this code:</p>
  <pre><code>public class SaveFooCommandHandler : ICommandHandler&lt;SaveFooCommand&gt;
  {
     private readonly IBusinessContext context;
  
     public SaveFooCommandHandler(IBusinessContext context)
     {
        this.context = context;
     }
  
     public async Task Handle(SaveFooCommand command)
     {
        var foos = (await Task.WhenAll(command.Foos.Select(foo =&gt; context.FindAsync&lt;Foo&gt;(foo.Id))).ToList()
  
        ...
     }
  }
  </code></pre>
  <p>That will fail, but</p>
  <pre><code>var foos = await context.AwaitAllAsync(command.Foos.Select(foo =&gt; context.FindAsync&lt;Foo&gt;(foo.Id));
  </code></pre>
  <p>will not, <code>context.FindAsync</code> is an abstraction of <code>dbcontext.Set&lt;T&gt;().FindAsync</code></p>
  <p>You could do <code>await context.Set&lt;Foo&gt;().Where(f =&gt; command.Foos.Contains(f.Id)).ToListAsync()</code>, but the example is simplified.</p>