How to create a Signal or Stream which only output when the input have been stopped for a period of time?
What I want to achieve is the following:
S1 : S - - S S S S - - - - - S S S S - - - -
S2 : - - - - - - - - - S - - - - - - - - S -
I would like to transform S1 into S2, which only output the last event if event has stopped for 3 - (where - is x seconds).
Use the method
throttle:, which waits for x seconds for another signal before sending through a next.
This is C# code, but you should be able to translate:
string xs = "S--SSSS-----SSSS----"; IObservable<char> source = Observable .Interval(TimeSpan.FromSeconds(1.0)) .Zip(xs.ToCharArray(), (n, c) => c) .Where(c => c == 'S'); IObservable<char> query = source .Select(x => Observable .Timer(TimeSpan.FromSeconds(3.0)) .Select(y => x)) .Switch();
This produces the two values at the correct time.
Ok. After googling I found what exactly I want. http://reactivex.io/documentation/operators/debounce.html