title: Preferred method for generating an IObservable<String> from a Stream
body: <p>As part of our application (in production for about 4 months now) we have a stream of data coming from an external device that we convert to an IObservable </p>
  
  <p>Up until now we've been using the following to generate it, and it's been working quite well.</p>
  
  <pre><code>IObservable&lt;string&gt; ObserveStringStream(Stream inputStream)
  {
      var streamReader = new StreamReader(inputStream);
      return Observable
              .Create&lt;string&gt;(observer =&gt; Scheduler.ThreadPool
              .Schedule(() =&gt; ReadLoop(streamReader, observer)));
  }
  
  private void ReadLoop(StreamReader reader, IObserver&lt;string&gt; observer)
  {
      while (true)
      {
          try
          {
              var line = reader.ReadLine();
              if (line != null)
              {
                  observer.OnNext(line);
              }
              else
              {
                  observer.OnCompleted();
                  break;
              }
          }
          catch (Exception ex)
          {
              observer.OnError(ex);
              break;
          }
      }
  }
  </code></pre>
  
  <p>Last night I wondered if there was a way to use the <code>yield return</code> syntax to achieve the same result and came up with this:</p>
  
  <pre><code>IObservable&lt;string&gt; ObserveStringStream(Stream inputStream)
  {
      var streamReader = new StreamReader(inputStream);
      return ReadLoop(streamReader)
              .ToObservable(Scheduler.ThreadPool);
  }
  
  private IEnumerable&lt;string&gt; ReadLoop(StreamReader reader)
  {
      while (true)
      {
          var line = reader.ReadLine();
          if (line != null)
          {
              yield return line;
          }
          else
          {
              yield break;
          }
      }
  }
  </code></pre>
  
  <p>It seems to work quite well and it's much cleaner, but I was wondering if there were any pros or cons for one way over the other, or if there was a better way entirely.</p>