Let\'s say I have an instant messaging app that plays a beep sound every time a message arrives. I want to debounce the beeps, but I\'d like to play the beep so
Window is a great solution, but I find the sample operator more intuitive and also with correct behavior.
messagesHandler.messages
.sample(Observable.timer(0.0, period: 2.0, scheduler: MainScheduler.instance))
.subscribeNext { [weak self] message in
self?.playMessageArrivedSound()
}.addDisposableTo(self.disposeBag)
The throttle operation does not do what I thought it should.
For people that also find throttle is too confusing:
"throttle will only forward an event once the source observable has stopped sending events for the specified period of time. This does not work well with regular event delivery" for more details.
In this case, the filter you want is
sample(Observable.timer(0.0, period: 2.0, scheduler: MainScheduler.instance))