RxView.debounce等待debounce的时间执行命令,如何立即执行命令?
RxView.debounce waits for the period of the debounce to execute the command, how do I execute the command right away?
我的 Android 应用程序中有以下代码,试图防止多次点击按钮:
RxView.clicks(bSubmit)
.debounce(2500, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(c -> displayToast());
但不是执行代码,然后防止在同一时间跨度内进行多次点击,
这段代码的作用是,它在去抖动时间跨度过去后执行命令。
我怎样才能达到我想要的?
根据 Reactivex.io documentation,debounce
在 window 时间发出最后一个事件。
您想要的是在时间 window 期间发出 第一个 事件,这是 throttleFirst
的作用(请参阅 documentation)。
RxView.clicks(bSubmit)
.throttleFirst(2500, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(c -> displayToast());
我的 Android 应用程序中有以下代码,试图防止多次点击按钮:
RxView.clicks(bSubmit)
.debounce(2500, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(c -> displayToast());
但不是执行代码,然后防止在同一时间跨度内进行多次点击, 这段代码的作用是,它在去抖动时间跨度过去后执行命令。
我怎样才能达到我想要的?
根据 Reactivex.io documentation,debounce
在 window 时间发出最后一个事件。
您想要的是在时间 window 期间发出 第一个 事件,这是 throttleFirst
的作用(请参阅 documentation)。
RxView.clicks(bSubmit)
.throttleFirst(2500, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(c -> displayToast());