title: 'WaitFor' an observable
body: <p>I'm in a situation where I have a list of Tasks that I'm working through (enable drive, change position, wait for stop, disable).</p>
  <p>The 'wait for' monitors an <code>IObservable&lt;Status&gt;</code>, which I want to wait on (so I can thread it through <code>ContinueWith</code> and the other tasks).</p>
  <p>I started out with the following tasks <em>inside</em> the OnNext handling of the subscriber, but that was just ugly. What I've now come up with is this extension method:</p>
  <pre><code>public static Task&lt;T&gt; WaitFor&lt;T&gt;(this IObservable&lt;T&gt; source, Func&lt;T, bool&gt; pred)
  {
      var tcs = new TaskCompletionSource&lt;T&gt;();
      source
          .Where(pred)
          .DistinctUntilChanged()
          .Take(1)  //OnCompletes the observable, subscription will self-dispose
          .Subscribe(val =&gt; tcs.TrySetResult(val),
                      ex =&gt; tcs.TrySetException(ex),
                      () =&gt; tcs.TrySetCanceled());
  
      return tcs.Task;
  }
  </code></pre>
  <p>(<strong>UPDATED</strong> with svick's suggestion of handling <code>OnCompleted</code> and <code>OnError</code>)</p>
  <h3>Questions:</h3>
  <ul>
  <li>Is this good, bad, or ugly?</li>
  <li>Did I miss an existing extension which could have done this?</li>
  <li>Are the <code>Where</code> and <code>DistinctUntilChanged</code> in the right order? (I <em>think</em> they are)</li>
  </ul>