Use case: I'm writing a thing that monitors changes and saves automatically. I want to Throttle so that I don't save more often than every five seconds. I want to save every 30 seconds if there is a continuous stream of changes.
Could not find observable.Throttle(mergeTime, maxTime) in the docs and could only think of ugly ways of writing my own so hence this question.
Here's a way to do it using
GroupByUntil
:And here's a way to do it using
Window
:Here is an interactive marble diagram (drag the input marbles around):
And here is a unit test that uses
TestScheduler
to control the clock and take the randomness of the system clock out of it:Here's the complete unit test code.