I am trying to prevent rapid clicks with plain/pure RxJava using throttleLast. The below code executes fine, but the blockingSubscribe code block never gets called. Am I missing something?
I am not looking for any suggestions around JakeWharton/RxBinding. I am using only RxJava.
Code:
fun previousDateOnClick(view: View) {
val time = System.currentTimeMillis()
Timber.d("previousButtonClick time=%s", time)
Observable.just(time)
.throttleLast(500, TimeUnit.MILLISECONDS)
.blockingSubscribe {
Timber.d("blockingSubscribe throttleLast time=%s", time)
}
}
Log Output:
2020-03-09 16:29:11.367 D: previousButtonClick time=1583751551367
2020-03-09 16:29:11.535 D: previousButtonClick time=1583751551535
2020-03-09 16:29:11.705 D: previousButtonClick time=1583751551704
2020-03-09 16:29:11.858 D: previousButtonClick time=1583751551857
2020-03-09 16:29:12.009 D: previousButtonClick time=1583751552009
2020-03-09 16:29:12.169 D: previousButtonClick time=1583751552169
2020-03-09 16:29:12.321 D: previousButtonClick time=1583751552320
2020-03-09 16:29:12.475 D: previousButtonClick time=1583751552474
2020-03-09 16:29:12.634 D: previousButtonClick time=1583751552633
2020-03-09 16:29:12.794 D: previousButtonClick time=1583751552793
2020-03-09 16:29:12.954 D: previousButtonClick time=1583751552953
2020-03-09 16:29:13.114 D: previousButtonClick time=1583751553114
2020-03-09 16:29:13.977 D: previousButtonClick time=1583751553976
2020-03-09 16:29:14.221 D: previousButtonClick time=1583751554220
2020-03-09 16:29:14.415 D: previousButtonClick time=1583751554414
2020-03-09 16:29:14.610 D: previousButtonClick time=1583751554609
2020-03-09 16:29:14.786 D: previousButtonClick time=1583751554786
2020-03-09 16:29:14.958 D: previousButtonClick time=1583751554957
2020-03-09 16:29:15.133 D: previousButtonClick time=1583751555132
2020-03-09 16:29:15.311 D: previousButtonClick time=1583751555310
2020-03-09 16:29:15.487 D: previousButtonClick time=1583751555486
2020-03-09 16:29:15.606 D: previousButtonClick time=1583751555605
This thread is not a duplicate of Preventing rapid clicks with RXJava, because there the question is not about preventing rapid click using pure/plain RxJava I can see some third party suggestions there. I implemented whatever is the accepted answer there but still, I am unable to achieve it and I am not interested in other libraries.