title: Webapi2 - Return from controller action after one task completes, but continue with further Async processing
body: <p>I have a question about Webapi2</p>
  
  <p>My application is fully <code>async/await</code>, but I want to optimize the last part. I have a hard time finding out, so is there any way to do the  following?</p>
  
  <p>An example of a webapi2 controller:</p>
  
  <pre><code> private async Task&lt;Foo&gt; Barfoo(Bar foo)
   {
       //some async function
   }     
  
   public async Task&lt;IHttpActionResult&gt; Foo(Bar bar)
   {
       List&lt;Task&gt; tasks=new List&lt;Task&gt;();
       var actualresult=Barfoo(bar.Bar);
       tasks.Add(actualresult);
       foreach(var foobar in bar.Foo)
       {
           //some stuff which fills tasks
       }
       await Task.WhenAll(tasks);
       return Ok(actualresult.Result);
   }
  </code></pre>
  
  <p>Just one function is needed for the client, so what I want is more like this:</p>
  
  <pre><code> private async Task&lt;Foo&gt; Barfoo(Bar foo)
   {
     //some async function  
   }     
  
   public async Task&lt;IHttpActionResult&gt; Foo(Bar bar)
   {
       List&lt;Task&gt; tasks=new List&lt;Task&gt;();
       var actualresult=Barfoo(bar.Bar);
       return Ok(actualresult.Result);
  
       foreach(var foobar in bar.Foo)
       {
           //some stuff which fills tasks for extra logic, not important for the client
       }
  
       await Task.WhenAll(tasks);
   }
  </code></pre>