是否有任何方法RxJava
可以重新检查变量是否为空,例如,每 1 秒重新检查一次或将值赋予变量时?
String x;
Completable.create(emitter -> {
if (x != null)
emitter.onComplete();
}).timeout(10, TimeUnit.SECONDS).subscribe();
是的,开始一个间隔并在其他一些运算符中读取变量的值。请注意,您需要一个volatile
变量才能安全:
volatile String x;
Observable.interval(1, TimeUnit.SECONDS)
.takeUntil(t -> x != null)
.ignoreElements()
.subscribe(() -> System.out.println("Done!"));
Observable.timer(3500, TimeUnit.MILLISECONDS)
.subscribe(t -> { x = "value"; });
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句