title: How to achieve sequence of timeouts with RX?
body: <p>The scenario is as follows: a device communicating over is considered connected if it makes a callback to the server within a short period of time.
  I want to create a class that encapsulates the functionality of keeping track of this status. On call to the device, the timeout should be reset. On callback, the connection is confirmed, and the status should be set to <em>true</em>, if the callback times out, it should be set to <em>false</em>. But the next call should be able to reset the timeout again indifferent to the current status.</p>
  
  <p>I was thinking to achieve this with RX using <code>swith</code> and <code>timeout</code>. But I don't know why it stops working.</p>
  
  <pre><code>public class ConnectionStatus
  {
  private Subject&lt;bool&gt; pending = new Subject&lt;bool&gt;();
  private Subject&lt;bool&gt; connected = new Subject&lt;bool&gt;();
  
  public bool IsConnected { get; private set; }
  
  public ConnectionStatus(CancellationToken token, short timeoutSeconds = 15)
  {
      pending.Select(outer =&gt; connected.Timeout(TimeSpan.FromSeconds(timeoutSeconds))) 
          .Switch()
          .Subscribe(_ =&gt; IsConnected = true, e =&gt; IsConnected = false, token);
  }
  
  public void ConfirmConnected()
  {
      connected.OnNext(true);
  }
  
  public void SetPending()
  {
      pending.OnNext(true);
  }
  }
  </code></pre>
  
  <p>This is the "test case":</p>
  
  <pre><code>var c = new ConnectionStatus(default(CancellationToken));
  
  c.SetPending();
  await Task.Delay(TimeSpan.FromSeconds(5));
  c.ConfirmConnected();   
  c.IsConnected.Dump(); // TRUE, OK
  
  c.SetPending();
  await Task.Delay(TimeSpan.FromSeconds(5));
  c.ConfirmConnected();
  c.IsConnected.Dump(); // TRUE, OK
  
  c.SetPending();
  await Task.Delay(TimeSpan.FromSeconds(20));
  c.IsConnected.Dump(); // FALSE, OK
  c.ConfirmConnected(); 
  c.IsConnected.Dump(); // FALSE, OK
  
  c.SetPending();
  await Task.Delay(TimeSpan.FromSeconds(10));
  c.ConfirmConnected(); 
  c.IsConnected.Dump(); // FALSE, NOT OK!
  </code></pre>
  
  <p>I assume that the timeout of the inner observable is also stopping the outer observable. As the <code>outer =&gt;</code> lambda is not called anymore. What is the correct way?</p>
  
  <p>Thank you</p>