0
我有一個測試案例採取和防抖動使用率問題
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
出現在日誌中兩次,爲什麼去抖延遲不起作用。有人可以幫忙嗎?