本文整理了Java中io.reactivex.Observable.blockingFirst()
方法的一些代码示例,展示了Observable.blockingFirst()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.blockingFirst()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:blockingFirst
[英]Returns the first item emitted by this Observable, or throws NoSuchElementException if it emits no items.
Scheduler: blockingFirst does not operate by default on a particular Scheduler.
[中]返回此Observable发出的第一个项,如果它不发出任何项,则抛出NosTouchElementException。
调度程序:blockingFirst默认情况下不会在特定调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public Integer apply(Integer v) throws Exception {
Observable.just(1).delay(10, TimeUnit.SECONDS).blockingFirst();
return v;
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public Integer apply(Integer v) throws Exception {
Observable.just(1).delay(10, TimeUnit.SECONDS).blockingFirst();
return v;
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public Integer apply(Integer v) throws Exception {
return Observable.just(2).delay(100, TimeUnit.MILLISECONDS).blockingFirst();
}
})
代码示例来源:origin: ReactiveX/RxJava
@Test
public void blockingFirstNormal() {
assertEquals(1, Observable.just(1, 2).blockingFirst(3).intValue());
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NoSuchElementException.class)
public void blockingFirstEmpty() {
Observable.empty().blockingFirst();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testBackpressureWithNoInitialValueObservable() throws InterruptedException {
Observable<Integer> source = Observable.just(1, 2, 3, 4, 5, 6);
Observable<Integer> reduced = source.reduce(sum).toObservable();
Integer r = reduced.blockingFirst();
assertEquals(21, r.intValue());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testWithFollowingFirstObservable() {
Observable<Integer> o = Observable.just(1, 3, 2, 5, 4);
assertEquals(Arrays.asList(1, 2, 3, 4, 5), o.toSortedList().toObservable().blockingFirst());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void blockingFirstDefault() {
assertEquals(1, Observable.<Integer>empty()
.subscribeOn(Schedulers.computation()).blockingFirst(1).intValue());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void blockingFirst() {
assertEquals(1, Observable.range(1, 10)
.subscribeOn(Schedulers.computation()).blockingFirst().intValue());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testBackpressureWithInitialValueObservable() throws InterruptedException {
Observable<Integer> source = Observable.just(1, 2, 3, 4, 5, 6);
Observable<Integer> reduced = source.reduce(0, sum).toObservable();
Integer r = reduced.blockingFirst();
assertEquals(21, r.intValue());
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 30000)
public void testIssue1527Observable() throws InterruptedException {
//https://github.com/ReactiveX/RxJava/pull/1527
Observable<Integer> source = Observable.just(1, 2, 3, 4, 5, 6);
Observable<Integer> reduced = source.reduce(new BiFunction<Integer, Integer, Integer>() {
@Override
public Integer apply(Integer i1, Integer i2) {
return i1 + i2;
}
}).toObservable();
Integer r = reduced.blockingFirst();
assertEquals(21, r.intValue());
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void testIssue1935NoUnsubscribeDownstream() {
Observable<Integer> source = Observable.just(1).isEmpty()
.flatMapObservable(new Function<Boolean, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Boolean t1) {
return Observable.just(2).delay(500, TimeUnit.MILLISECONDS);
}
});
assertEquals((Object)2, source.blockingFirst());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testListWithBlockingFirstObservable() {
Observable<String> o = Observable.fromIterable(Arrays.asList("one", "two", "three"));
List<String> actual = o.toList().toObservable().blockingFirst();
Assert.assertEquals(Arrays.asList("one", "two", "three"), actual);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void timerDelayZero() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
for (int i = 0; i < 1000; i++) {
Observable.timer(0, TimeUnit.MILLISECONDS).blockingFirst();
}
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void testIssue1935NoUnsubscribeDownstreamObservable() {
Observable<Integer> source = Observable.just(1).isEmpty().toObservable()
.flatMap(new Function<Boolean, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Boolean t1) {
return Observable.just(2).delay(500, TimeUnit.MILLISECONDS);
}
});
assertEquals((Object)2, source.blockingFirst());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testErrorThrownIssue1685() {
Subject<Object> subject = ReplaySubject.create();
Observable.error(new RuntimeException("oops"))
.materialize()
.delay(1, TimeUnit.SECONDS)
.dematerialize(Functions.<Notification<Object>>identity())
.subscribe(subject);
subject.subscribe();
subject.materialize().blockingFirst();
System.out.println("Done");
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void testIssue1935NoUnsubscribeDownstream() {
Observable<Integer> source = Observable.just(1)
.all(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return false;
}
})
.flatMapObservable(new Function<Boolean, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Boolean t1) {
return Observable.just(2).delay(500, TimeUnit.MILLISECONDS);
}
});
assertEquals((Object)2, source.blockingFirst());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFollowingFirstObservable() {
Observable<Integer> o = Observable.fromArray(1, 3, 5, 6);
Observable<Boolean> allOdd = o.all(new Predicate<Integer>() {
@Override
public boolean test(Integer i) {
return i % 2 == 1;
}
}).toObservable();
assertFalse(allOdd.blockingFirst());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testWithFollowingFirstObservable() {
Observable<Integer> o = Observable.fromArray(1, 3, 5, 6);
Observable<Boolean> anyEven = o.any(new Predicate<Integer>() {
@Override
public boolean test(Integer i) {
return i % 2 == 0;
}
}).toObservable();
assertTrue(anyEven.blockingFirst());
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void testIssue1935NoUnsubscribeDownstreamObservable() {
Observable<Integer> source = Observable.just(1)
.all(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return false;
}
}).toObservable()
.flatMap(new Function<Boolean, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Boolean t1) {
return Observable.just(2).delay(500, TimeUnit.MILLISECONDS);
}
});
assertEquals((Object)2, source.blockingFirst());
}
内容来源于网络,如有侵权,请联系作者删除!