本文整理了Java中io.reactivex.Single.ambArray()
方法的一些代码示例,展示了Single.ambArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Single.ambArray()
方法的具体详情如下:
包路径:io.reactivex.Single
类名称:Single
方法名:ambArray
[英]Runs multiple Single sources and signals the events of the first one that signals (cancelling the rest). Scheduler: ambArray does not operate by default on a particular Scheduler.
[中]运行多个单一来源,并向第一个发出信号的来源发送事件信号(取消其余来源)。调度程序:默认情况下,ambArray不会在特定调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void ambArrayNull() {
Single.ambArray((Single<Integer>[])null);
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Signals the event of this or the other SingleSource whichever signals first.
* <p>
* <img width="640" height="463" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.ambWith.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code ambWith} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
* @param other the other SingleSource to race for the first emission of success or error
* @return the new Single instance. A subscription to this provided source will occur after subscribing
* to the current source.
* @since 2.0
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public final Single<T> ambWith(SingleSource<? extends T> other) {
ObjectHelper.requireNonNull(other, "other is null");
return ambArray(this, other);
}
代码示例来源:origin: redisson/redisson
/**
* Signals the event of this or the other SingleSource whichever signals first.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code ambWith} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
* @param other the other SingleSource to race for the first emission of success or error
* @return the new Single instance. A subscription to this provided source will occur after subscribing
* to the current source.
* @since 2.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@SuppressWarnings("unchecked")
public final Single<T> ambWith(SingleSource<? extends T> other) {
ObjectHelper.requireNonNull(other, "other is null");
return ambArray(this, other);
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void ambArrayOneIsNull() {
Single.ambArray(null, just1)
.test()
.assertError(NullPointerException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void ambArrayEmpty() {
Single.ambArray()
.test()
.assertFailure(NoSuchElementException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void ambArrayOrder() {
Single<Integer> error = Single.error(new RuntimeException());
Single.ambArray(Single.just(1), error).test().assertValue(1);
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void ambSingleSource() {
assertSame(Single.never(), Single.ambArray(Single.never()));
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void noWinnerSuccessDispose() throws Exception {
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
final AtomicBoolean interrupted = new AtomicBoolean();
final CountDownLatch cdl = new CountDownLatch(1);
Single.ambArray(
Single.just(1)
.subscribeOn(Schedulers.single())
.observeOn(Schedulers.computation()),
Single.never()
)
.subscribe(new BiConsumer<Object, Throwable>() {
@Override
public void accept(Object v, Throwable e) throws Exception {
assertNotNull(v);
assertNull(e);
interrupted.set(Thread.currentThread().isInterrupted());
cdl.countDown();
}
});
assertTrue(cdl.await(500, TimeUnit.SECONDS));
assertFalse("Interrupted!", interrupted.get());
}
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void noWinnerErrorDispose() throws Exception {
final TestException ex = new TestException();
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
final AtomicBoolean interrupted = new AtomicBoolean();
final CountDownLatch cdl = new CountDownLatch(1);
Single.ambArray(
Single.error(ex)
.subscribeOn(Schedulers.single())
.observeOn(Schedulers.computation()),
Single.never()
)
.subscribe(new BiConsumer<Object, Throwable>() {
@Override
public void accept(Object v, Throwable e) throws Exception {
assertNull(v);
assertNotNull(e);
interrupted.set(Thread.currentThread().isInterrupted());
cdl.countDown();
}
});
assertTrue(cdl.await(500, TimeUnit.SECONDS));
assertFalse("Interrupted!", interrupted.get());
}
}
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void error() {
Single.ambArray(Single.error(new TestException()), Single.just(1))
.test()
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void nullSourceSuccessRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final Subject<Integer> ps = ReplaySubject.create();
ps.onNext(1);
@SuppressWarnings("unchecked")
final Single<Integer> source = Single.ambArray(ps.singleOrError(), Single.<Integer>never(), Single.<Integer>never(), null);
Runnable r1 = new Runnable() {
@Override
public void run() {
source.test();
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
ps.onComplete();
}
};
TestHelper.race(r1, r2);
if (!errors.isEmpty()) {
TestHelper.assertError(errors, 0, NullPointerException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
代码示例来源:origin: ReactiveX/RxJava
final Subject<Integer> ps2 = PublishSubject.create();
Single.ambArray(ps1.singleOrError(), ps2.singleOrError()).test();
代码示例来源:origin: ReactiveX/RxJava
final Subject<Integer> ps2 = PublishSubject.create();
Single.ambArray(ps1.singleOrError(), ps2.singleOrError()).test();
内容来源于网络,如有侵权,请联系作者删除!