本文整理了Java中io.reactivex.Single.timeout()
方法的一些代码示例,展示了Single.timeout()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Single.timeout()
方法的具体详情如下:
包路径:io.reactivex.Single
类名称:Single
方法名:timeout
[英]Signals a TimeoutException if the current Single doesn't signal a success value within the specified timeout window. Scheduler: timeout signals the TimeoutException on the computation Scheduler.
[中]如果当前信号在指定的超时窗口内未发出成功值的信号,则表示TimeoutException。调度器:超时向计算调度器发送TimeoutException信号。
代码示例来源:origin: Polidea/RxAndroidBle
@Override
public Single<BluetoothGatt> apply(Single<BluetoothGatt> bluetoothGattSingle) {
return autoConnect
? bluetoothGattSingle
: bluetoothGattSingle
.timeout(connectTimeout.timeout, connectTimeout.timeoutTimeUnit, connectTimeout.timeoutScheduler,
prepareConnectionTimeoutError());
}
};
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void timeoutUnitNull() {
just1.timeout(1, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void timeoutSchedulerNull() {
just1.timeout(1, TimeUnit.SECONDS, (Scheduler)null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void timeoutOther2Null() {
just1.timeout(1, TimeUnit.SECONDS, (Single<Integer>)null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void timeoutOtherNull() {
just1.timeout(1, TimeUnit.SECONDS, Schedulers.single(), null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void timeout() throws Exception {
Single.never().timeout(100, TimeUnit.MILLISECONDS, Schedulers.io())
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertFailure(TimeoutException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void timeoutOther() throws Exception {
Single.never()
.timeout(100, TimeUnit.MILLISECONDS, Schedulers.io(), Single.just(1))
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void mainSuccess() {
Single.just(1)
.timeout(1, TimeUnit.DAYS)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void mainError() {
Single.error(new TestException())
.timeout(1, TimeUnit.DAYS)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void mainTimedOut() {
Single
.never()
.timeout(1, TimeUnit.NANOSECONDS)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertFailureAndMessage(TimeoutException.class, timeoutMessage(1, TimeUnit.NANOSECONDS));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalSuccessDoesntDisposeMain() {
final int[] calls = { 0 };
Single.just(1)
.doOnDispose(new Action() {
@Override
public void run() throws Exception {
calls[0]++;
}
})
.timeout(1, TimeUnit.DAYS)
.test()
.assertResult(1);
assertEquals(0, calls[0]);
}
代码示例来源:origin: Polidea/RxAndroidBle
@Override
final protected void protectedRun(final ObservableEmitter<T> emitter, final QueueReleaseInterface queueReleaseInterface)
throws Throwable {
final QueueReleasingEmitterWrapper<T> emitterWrapper = new QueueReleasingEmitterWrapper<>(emitter, queueReleaseInterface);
getCallback(rxBleGattCallback)
.timeout(
timeoutConfiguration.timeout,
timeoutConfiguration.timeoutTimeUnit,
timeoutConfiguration.timeoutScheduler,
timeoutFallbackProcedure(bluetoothGatt, rxBleGattCallback, timeoutConfiguration.timeoutScheduler)
)
.toObservable()
.subscribe(emitterWrapper);
if (!startOperation(bluetoothGatt)) {
emitterWrapper.cancel();
emitterWrapper.onError(new BleGattCannotStartException(bluetoothGatt, operationType));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void otherErrors() {
Single.never()
.timeout(1, TimeUnit.MILLISECONDS, Single.error(new TestException()))
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testTimeout() {
TestSubscriber<String> ts = new TestSubscriber<String>();
Single<String> s1 = Single.<String>unsafeCreate(new SingleSource<String>() {
@Override
public void subscribe(SingleObserver<? super String> observer) {
observer.onSubscribe(Disposables.empty());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// ignore as we expect this for the test
}
observer.onSuccess("success");
}
}).subscribeOn(Schedulers.io());
s1.timeout(100, TimeUnit.MILLISECONDS).toFlowable().subscribe(ts);
ts.awaitTerminalEvent();
ts.assertError(TimeoutException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testTimeoutWithFallback() {
TestSubscriber<String> ts = new TestSubscriber<String>();
Single<String> s1 = Single.<String>unsafeCreate(new SingleSource<String>() {
@Override
public void subscribe(SingleObserver<? super String> observer) {
observer.onSubscribe(Disposables.empty());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// ignore as we expect this for the test
}
observer.onSuccess("success");
}
}).subscribeOn(Schedulers.io());
s1.timeout(100, TimeUnit.MILLISECONDS, Single.just("hello")).toFlowable().subscribe(ts);
ts.awaitTerminalEvent();
ts.assertNoErrors();
ts.assertValue("hello");
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() {
final PublishSubject<String> subject = PublishSubject.create();
final TestScheduler scheduler = new TestScheduler();
final TestObserver<String> observer = subject.single("")
.timeout(100, TimeUnit.MILLISECONDS, scheduler)
.test();
assertTrue(subject.hasObservers());
observer.dispose();
assertFalse(subject.hasObservers());
}
代码示例来源:origin: com.microsoft.rest.v2/client-runtime
@Override
public Single<HttpResponse> sendAsync(HttpRequest request) {
return next.sendAsync(request).timeout(timeout, unit);
}
}
代码示例来源:origin: gentics/mesh
@Override
public Single<Boolean> isAvailable() {
try {
return client.clusterHealth().async()
.timeout(1, TimeUnit.SECONDS)
.map(ignore -> true)
.onErrorReturnItem(false);
} catch (HttpErrorException e) {
return Single.just(false);
}
}
代码示例来源:origin: gentics/mesh
@Override
public Single<JsonObject> getDocument(String index, String uuid) {
String fullIndex = installationPrefix() + index;
return client.getDocument(fullIndex, DEFAULT_TYPE, uuid).async()
.map(response -> {
if (log.isDebugEnabled()) {
log.debug("Get object {" + uuid + "} from index {" + fullIndex + "}");
}
return response;
}).timeout(getOptions().getTimeout(), TimeUnit.MILLISECONDS).doOnError(error -> {
log.error("Could not get object {" + uuid + "} from index {" + fullIndex + "}", error);
});
}
代码示例来源:origin: AppStoreFoundation/asf-sdk
@Override public BigInteger get(ByteArray createChannelTxHash) {
return Observable.fromCallable(
() -> web3j.ethGetTransactionReceipt(createChannelTxHash.toHexString(true))
.send()
.getTransactionReceipt())
.retryWhen(flowable -> flowable.zipWith(Observable.interval(period, TimeUnit.SECONDS),
(throwable, integer) -> integer))
.singleOrError()
.timeout(timeout, TimeUnit.SECONDS,
Single.error(new TransactionNotFoundException(createChannelTxHash.toHexString())))
.map(org.web3j.protocol.core.methods.response.TransactionReceipt::getBlockNumber)
.blockingGet();
}
}
内容来源于网络,如有侵权,请联系作者删除!