有没有办法(运算符)来缩小/增强下面的代码?
我想获取Observable 的第一个元素,但延迟其完成,直到源完成(这就是我使用 进行连接的原因ignoreElements)。
public class SOTest {
private final TestScheduler scheduler = new TestScheduler();
@Test
public void take_first_and_do_not_complete() {
TestObserver<Long> test = Observable.interval(1, TimeUnit.SECONDS, scheduler)
.take(7)
.publish(o -> o
.firstElement()
.toObservable()
.concatWith(o
.doOnNext(e -> System.out.println("to be ignored: " + e))
.ignoreElements()
)
)
.doOnNext(e -> System.out.println("First is: " + e))
.test();
scheduler.advanceTimeTo(1, TimeUnit.SECONDS);
test.assertValueCount(1);
test.assertNotComplete();
scheduler.advanceTimeTo(5, TimeUnit.SECONDS);
test.assertValueCount(1);
test.assertNotComplete();
scheduler.advanceTimeTo(7, TimeUnit.SECONDS);
test.assertValueCount(1);
test.assertComplete();
}
}
白衣染霜花
相关分类