title: Returning IAsyncEnumerable<T> and NotFound from Asp.Net Core Controller
body: <p>What is the right signature for a controller action that returns an <code>IAsyncEnumerable&lt;T&gt;</code> and a <code>NotFoundResult</code> but is still processed in an async fashion?</p>
  <p>I used this signature and it doesn't compile because <code>IAsyncEnumerable&lt;T&gt;</code> isn't awaitable:</p>
  <pre><code>[HttpGet]
  public async Task&lt;IActionResult&gt; GetAll(Guid id)
  {
      try
      {
          return Ok(await repository.GetAll(id)); // GetAll() returns an IAsyncEnumerable
      }
      catch (NotFoundException e)
      {
          return NotFound(e.Message);
      }
  }
  </code></pre>
  <p>This one compiles fine but its signature isn't async. So I'm worried whether it'll block thread pool threads or not:</p>
  <pre><code>[HttpGet]
  public IActionResult GetAll(Guid id)
  {
      try
      {
          return Ok(repository.GetAll(id)); // GetAll() returns an IAsyncEnumerable
      }
      catch (NotFoundException e)
      {
          return NotFound(e.Message);
      }
  }
  </code></pre>
  <p>I tried using a <code>await foreach</code> loop on like this but that obviously wouldn't compile either:</p>
  <pre><code>[HttpGet]
  public async IAsyncEnumerable&lt;MyObject&gt; GetAll(Guid id)
  {
      IAsyncEnumerable&lt;MyObject&gt; objects;
      try
      {
          objects = repository.GetAll(id); // GetAll() returns an IAsyncEnumerable
      }
      catch (NotFoundException e)
      {
          return NotFound(e.Message);
      }
  
      await foreach (var obj in objects)
      {
          yield return obj;
      }
  }
  </code></pre>