title: How would you correctly return a collection of objects asynchronously?
body: <p>I need to define methods in my core interface that return lists. My project heavily relies on the use of async/await so I need to define my core references/interfaces as asynchronous as possible. I also use EF7 for my data-access layer. I currently use <code>IAsyncEnumerable</code> everywhere.</p>
  
  <p>I am currently deciding whether to keep using <code>IAsyncEnumerable</code> or to revert back to using <code>Task&lt;IEnumerable&lt;T&gt;&gt;</code>. <code>IAsyncEnumerable</code> seems promising at this point. EF7 is <a href="https://github.com/aspnet/EntityFramework/issues/77" rel="nofollow noreferrer">using</a> it as well. The trouble is, I don't know and can't figure out how to use it. There is almost nothing on the <a href="http://rx.codeplex.com/documentation" rel="nofollow noreferrer">website</a> that tells anyone how to use <strong>Ix.Net</strong>. There's a <code>ToAsyncEnumerable</code> extension that I can use on <code>IEnumerable</code> objects but this wouldn't do anything asynchronously (or does it??). Another drawback is that given the below signature:</p>
  
  <pre><code>IAsyncEnumerable GetPersons();
  </code></pre>
  
  <p>Because this isn't a function that returns Task, I can't use async/await inside the function block.</p>
  
  <p>On the other hand, my gut is telling me that I should stick with using <code>Task&lt;IEnumerable&lt;T&gt;&gt;</code>. This of course has it's problems as well. EF does not have an extension method that returns this type. It has a <code>ToArrayAsync</code> and <code>ToListAsync</code> extension method but this of course requires you to call await inside the method because <code>Task&lt;T&gt;</code> isn't covariant. This potentially is a problem because this creates an extra <em>operation</em> which could be avoided if I simply return the <code>Task</code> object.</p>
  
  <p>My questions is: Should I keep using <code>IAsyncEnumerable</code> (preferred) or should I change everything back to <code>Task&lt;IEnumerable&lt;T&gt;&gt;</code> (not preferred)? I'm open to other suggestions as well.</p>