【发布时间】:2023-03-13 01:07:01
【问题描述】:
我有以下方法:
public class ParentalControlInteractor {
public Single<Boolean> isPinSet() {
return bamSdk.getPinManager().isPINSet();
}
}
我想调用这个函数运行一次,然后每分钟重复一次,直到无穷大,但这似乎很笨拙:
parentalControlInteractor.isPinSet()
.subscribeOn(Schedulers.io())
.repeat(10000)
.timeout(1600,TimeUnit.MILLISECONDS)
.doOnError(throwable -> {
Timber.e(throwable,"Error getting if Pin is set");
throwable.printStackTrace();
})
.subscribe(isPinSet -> {
this.isPinSet = isPinSet;
Timber.d("Pin is set = " + isPinSet.toString());
});
难道没有更好的方法吗?我正在使用 RxJava2。另外,上面的方法只调用了 10000 次。我想永远调用它,比如使用 Handler.postDelayed()。
【问题讨论】:
-
只需调用
repeat()不传递任何参数即可永久重复 -
我不希望它每秒都调用这个,我希望有一个间隔。