Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is the what I posted as an answer to this question in the <a href="http://social.msdn.microsoft.com/Forums/en-US/rx/thread/c1cd78b6-8b76-451f-9281-584bab3f4fec" rel="nofollow noreferrer">Rx forum</a>:</p> <p><strong>UPDATE</strong>: Here is a new version that does no longer delay event forwarding when events occur with a time difference of more than one second:</p> <pre><code>public static IObservable&lt;T&gt; ThrottleResponsive3&lt;T&gt;(this IObservable&lt;T&gt; source, TimeSpan minInterval) { return Observable.CreateWithDisposable&lt;T&gt;(o =&gt; { object gate = new Object(); Notification&lt;T&gt; last = null, lastNonTerminal = null; DateTime referenceTime = DateTime.UtcNow - minInterval; var delayedReplay = new MutableDisposable(); return new CompositeDisposable(source.Materialize().Subscribe(x =&gt; { lock (gate) { var elapsed = DateTime.UtcNow - referenceTime; if (elapsed &gt;= minInterval &amp;&amp; delayedReplay.Disposable == null) { referenceTime = DateTime.UtcNow; x.Accept(o); } else { if (x.Kind == NotificationKind.OnNext) lastNonTerminal = x; last = x; if (delayedReplay.Disposable == null) { delayedReplay.Disposable = Scheduler.ThreadPool.Schedule(() =&gt; { lock (gate) { referenceTime = DateTime.UtcNow; if (lastNonTerminal != null &amp;&amp; lastNonTerminal != last) lastNonTerminal.Accept(o); last.Accept(o); last = lastNonTerminal = null; delayedReplay.Disposable = null; } }, minInterval - elapsed); } } } }), delayedReplay); }); } </code></pre> <hr> <p>This was my earlier try:</p> <pre><code>var source = Observable.GenerateWithTime(1, x =&gt; x &lt;= 100, x =&gt; x, x =&gt; TimeSpan.FromMilliseconds(1), x =&gt; x + 1) .Timestamp(); source.Publish(o =&gt; o.Take(1).Merge(o.Skip(1).Sample(TimeSpan.FromSeconds(1))) ).Run(x =&gt; Console.WriteLine(x)); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload