我有下一个测试用例
public void testLimitAndPublishSubject() throws InterruptedException {
PublishSubject<Boolean> mBooleanPublishSubject = PublishSubject.create();
mBooleanPublishSubject.asObservable()
.doOnEach(__ -> System.out.println("on value emitted "+System.currentTimeMillis()))
.take(1)
.doOnEach(__ -> System.out.println("on value emitted 2 "+System.currentTimeMillis()))
.debounce(1000, TimeUnit.MILLISECONDS)
.doOnEach(__ -> System.out.println("on value emitted 3 "+System.currentTimeMillis()))
.subscribe(__ -> System.out.println("done "+System.currentTimeMillis()));
mBooleanPublishSubject.onNext(true);
Thread.sleep(1000);
mBooleanPublishSubject.onNext(true);
Thread.sleep(2000);
}
,输出
on value emitted 1454063289770
on value emitted 2 1454063289770
on value emitted 2 1454063289779
on value emitted 3 1454063289780
done 1454063289780
on value emitted 3 1454063289780
我无法弄清楚为什么on value emitted 2
和on value emitted 3
出现在日志中两次以及为什么去抖延迟不起作用。有人可以帮忙吗?
答案 0 :(得分:0)
讨论here
要解决日志问题中的重复项目,我应该使用std::system("color 4");
std::cout << "Incorrect Password\n";
而不是doOnNext
,例如doOnEach包含doOnEach
个事件
onCompleted
立即完成观察,这就是为什么去抖不起作用的原因。应该使用延迟而不是
take(1)