本文整理了Java中io.reactivex.Observable.amb()
方法的一些代码示例,展示了Observable.amb()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.amb()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:amb
[英]Mirrors the one ObservableSource in an Iterable of several ObservableSources that first either emits an item or sends a termination notification.
Scheduler: amb does not operate by default on a particular Scheduler.
[中]镜像多个可观察资源中的一个可观察资源,这些可观察资源首先发出一个项目或发送终止通知。
调度器:默认情况下,amb不会在特定的调度器上运行。
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void ambIterableNull() {
Observable.amb((Iterable<Observable<Object>>)null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void manySources() {
Observable<?>[] a = new Observable[32];
Arrays.fill(a, Observable.never());
a[31] = Observable.just(1);
Observable.amb(Arrays.asList(a))
.test()
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void singleIterable() {
Observable.amb(Collections.singletonList(Observable.just(1)))
.test()
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void ambIterableOrder() {
Observable<Integer> error = Observable.error(new RuntimeException());
Observable.amb(Arrays.asList(Observable.just(1), error)).test().assertValue(1).assertComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void emptyIterable() {
Observable.amb(Collections.<Observable<Integer>>emptyList())
.test()
.assertResult();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void ambIterableIteratorNull() {
Observable.amb(new Iterable<Observable<Object>>() {
@Override
public Iterator<Observable<Object>> iterator() {
return null;
}
}).test().assertError(NullPointerException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void ambIterableOneIsNull() {
Observable.amb(Arrays.asList(Observable.never(), null))
.test()
.assertError(NullPointerException.class);
}
代码示例来源:origin: Polidea/RxAndroidBle
/**
* A convenience function creating a transformer that will use two observables for completing the returned observable (and
* un-subscribing from the passed observable) beforeEmission will be used to complete the passed observable before it's first
* emission and afterEmission will be used to do the same after the first emission
*
* @param beforeEmission the observable that will control completing the returned observable before it's first emission
* @param afterEmission the observable that will control completing the returned observable after it's first emission
* @param <T> the type of the passed observable
* @return the observable
*/
@NonNull
private static <T> ObservableTransformer<T, T> takeUntil(Observable<?> beforeEmission, Observable<?> afterEmission) {
return observable -> observable.publish(publishedObservable -> {
final Observable<?> afterEmissionTakeUntil = publishedObservable
.take(1)
.ignoreElements()
.andThen(afterEmission);
return Observable.amb(
asList(
publishedObservable,
publishedObservable.takeUntil(beforeEmission)
))
.takeUntil(afterEmissionTakeUntil);
}
);
}
代码示例来源:origin: Polidea/RxAndroidBle
return Observable.amb(asList(
enableNotifyClicksObservable,
enableIndicateClicksObservable)
内容来源于网络,如有侵权,请联系作者删除!