title: Subscribing to observable sequence with async function
body: <p>I have an <code>asnyc</code> function that I want to invoke on every observation in an <code>IObservable</code> sequence, limiting delivery to one event at a time. The consumer  expects no more than one message in flight; and this is also the RX contract, if I understand it correctly.</p>
  
  <p>Consider this sample:</p>
  
  <pre><code>static void Main() {
    var ob = Observable.Interval(TimeSpan.FromMilliseconds(100));
    //var d = ob.Subscribe(async x =&gt; await Consume(x));  // Does not rate-limit.
    var d = ob.Subscribe(x =&gt; Consume(x).Wait());
    Thread.Sleep(10000);
    d.Dispose();
  }
  
  static async Task&lt;Unit&gt; Consume(long count) {
    Console.WriteLine($"Consuming {count} on thread {Thread.CurrentThread.ManagedThreadId}");
    await Task.Delay(750);
    Console.WriteLine($"Returning on thread {Thread.CurrentThread.ManagedThreadId}");
    return Unit.Default;
  }
  </code></pre>
  
  <p>The <code>Consume</code> function fakes a 750 ms processing time, and <code>ob</code> produces events every 100 ms. The code above works, but calls <code>task.Wait()</code> on a random thread. If I instead subscribe as in the commented out line 3, then <code>Consume</code> is invoked at the same rate at which <code>ob</code> produces events (and I cannot even grok what overload of <code>Subscribe</code> I am using in this commented statement, so it is probably nonsense).</p>
  
  <p>So how do I correctly deliver one event at a time from an observable sequence to an <code>async</code> function?</p>