AG is a mini-series on the quirks and idiosyncrasies of Android app development. Check out Part 2 here.

Debounce Operator

So debounce is a pretty cool operator in Rx. When you want to emit an item only after a certain amount of time has passed, debounce is there to rescue.

It helped me in identifying an idle user by listening to a stream of screen touch events and setting a timeout of 15 seconds.

If items keep being emitted by the source ObservableSource faster than the timeout then no items will be emitted by the resulting ObservableSource.

Testing Debounce

Now that I had solved the problem with debounce , it was time to write a small test and set it in stone.

Hit ^R to run the test and 💥

Gotcha

Looks like our sweet little debounce operator runs on its own sweet little scheduler and our TestScheduler wasn’t able to override it. Only took an entire day to figure that out! 🤦‍

Rescue Time

Pass a scheduler to debounce

and use the TestScheduler to test.

Hit ^R to run the test and ʕ•ᴥ•ʔ