I\'m working on an android project that makes requests through retrofit using Rx-Java observable and subscribe.
However, in some interactions this request can be cal
Suppose you want to start an execution according to some trigger event.
Observable<Event> trigger = ... // e.g. button clicks
You can transform the trigger events to calls to your API like this:
trigger
.debounce(1, TimeUnit.SECONDS)
.flatMap(event -> mApi.getOnlineUsers())
.subscribe(users -> showThemSomewhere(users));
Also, notice that the debounce
operator will take the last occurrence within the time frame, but throttlefirst
will take the first. You may want to use one or the other depending on your use case.