I have a liveData set up that emits some integers. but i would like to throttle the emissions such that it only happens every 5 seconds. but after the first 5 seconds have passed then the throttling can be removed.
here i am observing a count like this:
count1.observe(this, new Observer() {
@Override public void onChanged(@Nullable Integer i) {
//Do something with "integer"
}
});
but i want onChanged() callback to be throttled such that its just called maximum of 2 times within the first 5 seconds. After the first 5 seconds have passed i dont need the throttling anymore at all. Im not sure how to do this as i dont see any options for livedata to handle streams. i tried Transformation but it only has map and switchMap. how can this be done ? enter code here