title: Can I await an enumerable I create with a generator?
body: <p>Let's say I have a sequence of integers I obtain asynchronously. </p>
  
  <pre><code>async Task&lt;int&gt; GetI(int i){
      return await Task.Delay(1000).ContinueWith(x =&gt; i);
  }
  </code></pre>
  
  <p>I want to create a generator over that sequence, if the sequence was synchronous I'd do:</p>
  
  <pre><code>IEnumerable&lt;int&gt; Method()
  {
      for (var i = 0; i &lt; 100; i++)
      {
          yield return GetI(i); // won't work, since getI returns a task
      }
  }
  </code></pre>
  
  <p>So, I figured the analogy is making the generator async and yielding from it:</p>
  
  <pre><code>async Task&lt;IEnumerable&lt;int&gt;&gt; Method()    
  {
      for (var i = 0; i &lt; 100; i++)
      {
          yield return await Task.Delay(1000).ContinueWith(x =&gt; i);
      }
  }
  </code></pre>
  
  <p>This won't work, since a method with <code>yield</code> must return an <code>IEnumerable</code> of something, the alternative, which makes more sense is <code>IEnumerable&lt;Task&lt;int&gt;&gt;</code> but that won't compile since <code>async</code> methods must return <code>Task</code>s or void.</p>
  
  <p>Now, I realize I can simply remove the await and return an <code>IEnumerable&lt;Task&lt;int&gt;&gt;</code> but that won't help me since the iteration will keep asking for data before any of it is ready, so it doesn't solve my issue.</p>
  
  <ul>
  <li>Is there any way to nicely mix enumerables and tasks with the nice sugar the language gives me with await and yield?</li>
  <li>Is there any way to nicely consume it? </li>
  </ul>
  
  <p><sup>(From searching online, I suspect the answer to the first question is false and the second one is an observer/observable, but I couldn't find any canonical reference and I'm interested in the best way to implement this pattern in C#)</sup></p>