title: Rx: How to buffer events (ring buffer) and only flush them when a special event occurs?
body: <p>I'm using Reactive Extensions (Rx) in C# and want to filter events in the following way. Imagine I have the following originator sequence:</p>
  
  <p>A B C D E F <strong>X</strong> G H I <strong>X</strong> J <strong>X X</strong> K L M N O <strong>X</strong> P</p>
  
  <p>And I want to produce the following output:</p>
  
  <p>E F <strong>X</strong> H I <strong>X</strong> J <strong>X X</strong> N O <strong>X</strong></p>
  
  <p>Basically, I would buffer (throttle?) events with a max bound (in the example this bound is 2), and when I get certain event (in this case event X), I want to flush that buffer to the output and start buffering again until I see the special event again.</p>
  
  <p>I'm trying a few approaches but without any luck, and I imagine there should be an easy way to accomplish it that I am missing.</p>
  
  <p>EDIT: one constraint, is that I expect to get TONS of events that are discarded, and only a few instances of X, so keeping a buffer in memory with thousands of events to read only the last 2 (or 20) is not really an option.</p>