I have the following method that makes a request to get a pokemon from a endpoint.
I would like to prevent the user in making rapid requests by clicking quickly on the button that will invoke this method many times. I have used the throttle* methods and debounce.
Bascially, what I am looking for if the user rapidly clicks on the button within 300 milliseconds duration it should accept the last click in that duration. However, what i am experiencing is that all requests are being made. i.e. if the user rapidly clicks 3x within that duration I still get 3 requests.
fun getPokemonDetailByName(name: String) {
pokemonDetailInteractor.getPokemonDetailByName(name)
.subscribeOn(pokemonSchedulers.background())
.observeOn(pokemonSchedulers.ui())
.toObservable()
.throttleFirst(300, TimeUnit.MILLISECONDS)
.singleOrError()
.subscribeBy(
onSuccess = { pokemon ->
pokemonDetailLiveData.value = pokemon
},
onError = {
Timber.e(TAG, it.localizedMessage)
}
).addTo(compositeDisposable)
}