title: What is the correct way to use async/await in a recursive method?
body: <p>What is the correct way to use async/await in a recursive method? Here is my method:</p>
  
  <pre><code>public string ProcessStream(string streamPosition)
  {
      var stream = GetStream(streamPosition);
  
      if (stream.Items.count == 0)
          return stream.NextPosition;
  
      foreach(var item in stream.Items) {
          ProcessItem(item);
      }
  
      return ProcessStream(stream.NextPosition)
  }
  </code></pre>
  
  <p>And here is the method with async/await:</p>
  
  <pre><code>public async Task&lt;string&gt; ProcessStream(stringstreamPosition)
  {
          var stream = GetStream(streamPosition);
  
          if (stream.Items.count == 0)
              return stream.NextPosition;
  
          foreach(var item in stream.Items) {
              await ProcessItem(item); //ProcessItem() is now an async method
          }
  
          return await ProcessStream(stream.NextPosition);
   }
  </code></pre>