I have somewhat of a special need / requirement for an observable stream that goes a bit beyond normal throttling and I am not entirely sure how to do it:
Basically I have an observable Stream originally from a normal event like so:
var someEventObservable = Observable.FromEventPattern<SomeEventHandler, SomeEventArgs>(
handler => this.ColumnWidthChanged += handler,
handler => this.ColumnWidthChanged -= handler)
.Select(_ => Unit.Default);
Now as these events can happen in rapid succession and I only need to know whether it happened at least once within a given time frame, I would normally use .Throttle(), i.e. like so:
var someThrottledEventObservable = someEventObservable
.Throttle(TimeSpan.FromMilliseconds(300));
But my actual requirements go one step further: if an event was raised within that throttling TimeSpan / dueTime AND if yet another event is raised after the first event but still within that dueTime, I want the throttled stream to start over from 0 wait time again and wait another 300ms... and if another event was raised, re-start/extend that time again.. and so on and so on.
Only if no other event was raised within the original or restarted TimeSpan(s)/ dueTime the someThrottledEventObservable
should yield a new Unit instance.
I hope that makes sense - but basically I want/need a throttled stream of events that yields one event whenever the source stream has stopped yielding new events for a given time & if new events happen within that wait time the throttled stream should re-start waiting.
Or: In an ongoing 'storm' of events .Throttle() alone results in a new Unit every 300ms (in the example above) but I want exactly one new Unit whenever one or more events were fired but no new ones occurred within a 300ms coold-down-period thereafter.
How would I do that?