本文整理了Java中io.reactivex.Single.retry()
方法的一些代码示例,展示了Single.retry()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Single.retry()
方法的具体详情如下:
包路径:io.reactivex.Single
类名称:Single
方法名:retry
[英]Repeatedly re-subscribes to the current Single indefinitely if it fails with an onError. Scheduler: retry does not operate by default on a particular Scheduler.
[中]如果当前单曲出现错误,则反复无限期地重新订阅该单曲。调度程序:默认情况下,重试不会在特定调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void retryBiPreducateNull() {
error.retry((BiPredicate<Integer, Throwable>)null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void retryPredicateNull() {
error.retry((Predicate<Throwable>)null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void retryTimesPredicateWithMatchingPredicate() {
final AtomicInteger atomicInteger = new AtomicInteger(3);
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);
Single.fromCallable(new Callable<Boolean>() {
@Override public Boolean call() throws Exception {
numberOfSubscribeCalls.incrementAndGet();
if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}
throw new IllegalArgumentException();
}
})
.retry(Integer.MAX_VALUE, new Predicate<Throwable>() {
@Override public boolean test(final Throwable throwable) throws Exception {
return !(throwable instanceof IllegalArgumentException);
}
})
.test()
.assertFailure(IllegalArgumentException.class);
assertEquals(3, numberOfSubscribeCalls.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void retryTimesPredicateWithMatchingRetryAmount() {
final AtomicInteger atomicInteger = new AtomicInteger(3);
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);
Single.fromCallable(new Callable<Boolean>() {
@Override public Boolean call() throws Exception {
numberOfSubscribeCalls.incrementAndGet();
if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}
return true;
}
})
.retry(2, Functions.alwaysTrue())
.test()
.assertResult(true);
assertEquals(3, numberOfSubscribeCalls.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void retryTimesPredicateWithNotMatchingRetryAmount() {
final AtomicInteger atomicInteger = new AtomicInteger(3);
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);
Single.fromCallable(new Callable<Boolean>() {
@Override public Boolean call() throws Exception {
numberOfSubscribeCalls.incrementAndGet();
if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}
return true;
}
})
.retry(1, Functions.alwaysTrue())
.test()
.assertFailure(RuntimeException.class);
assertEquals(2, numberOfSubscribeCalls.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void retryTimesPredicateWithZeroRetries() {
final AtomicInteger atomicInteger = new AtomicInteger(2);
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);
Single.fromCallable(new Callable<Boolean>() {
@Override public Boolean call() throws Exception {
numberOfSubscribeCalls.incrementAndGet();
if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}
return true;
}
})
.retry(0, Functions.alwaysTrue())
.test()
.assertFailure(RuntimeException.class);
assertEquals(1, numberOfSubscribeCalls.get());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void retryBiPredicate() {
Single.fromCallable(new Callable<Object>() {
int c;
@Override
public Object call() throws Exception {
if (++c != 5) {
throw new TestException();
}
return 1;
}
})
.retry(new BiPredicate<Integer, Throwable>() {
@Override
public boolean test(Integer i, Throwable e) throws Exception {
return true;
}
})
.test()
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void retryPredicate() {
Single.fromCallable(new Callable<Object>() {
int c;
@Override
public Object call() throws Exception {
if (++c != 5) {
throw new TestException();
}
return 1;
}
})
.retry(new Predicate<Throwable>() {
@Override
public boolean test(Throwable e) throws Exception {
return true;
}
})
.test()
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void retry() {
Single.fromCallable(new Callable<Object>() {
int c;
@Override
public Object call() throws Exception {
if (++c != 5) {
throw new TestException();
}
return 1;
}
})
.retry()
.test()
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void retryTimes() {
Single.fromCallable(new Callable<Object>() {
int c;
@Override
public Object call() throws Exception {
if (++c != 5) {
throw new TestException();
}
return 1;
}
})
.retry(5)
.test()
.assertResult(1);
}
代码示例来源:origin: avluis/Hentoid
private void checkForUpdates() {
notificationManager.startForeground(new UpdateCheckNotification());
disposable = UpdateServer.API.getUpdateInfo()
.retry(3)
.observeOn(mainThread())
.doFinally(this::stopSelf)
.subscribe(this::onCheckSuccess, this::onCheckError);
}
代码示例来源:origin: akarnokd/akarnokd-misc
@Test
public void test() {
Single.just("input").flatMap(val ->
Single.using(
() -> {
System.out.println("create");
return "";
},
call -> singleSubscriber -> {
System.out.println("sub");
singleSubscriber.onSuccess(val);
System.out.println("sub done");
},
call -> {
System.out.println("close");
}
)
.retry((count, error) -> {
System.out.println("retry");
return true;
})
)
.subscribe(val -> System.out.println("output " + val));
}
}
代码示例来源:origin: oliexdev/openScale
/**
* Read bytes from a Bluetooth device.
*
* @note onBluetoothRead() will be triggered if read command was successful. nextMachineStep() needs to manually called!
*@param characteristic the Bluetooth UUID characteristic
*/
protected void readBytes(UUID characteristic) {
if (isConnected()) {
final Disposable disposable = connectionObservable
.firstOrError()
.flatMap(rxBleConnection -> rxBleConnection.readCharacteristic(characteristic))
.observeOn(AndroidSchedulers.mainThread())
.retry(BT_RETRY_TIMES_ON_ERROR)
.subscribe(bytes -> {
Timber.d("Read characteristic %s", BluetoothGattUuid.prettyPrint(characteristic));
onBluetoothRead(characteristic, bytes);
},
throwable -> onError(throwable)
);
compositeDisposable.add(disposable);
}
}
代码示例来源:origin: AppStoreFoundation/asf-sdk
@Override public Single<BDSChannel> createChannel(ECKey senderECKey, Address receiverAddress,
BigInteger balance) {
return Single.fromCallable(
() -> microRaidenClient.createChannel(senderECKey, receiverAddress, balance))
.map(openBlockNumber -> new BDSChannelImpl(senderECKey, receiverAddress, openBlockNumber,
microRaidenClient, bdsMicroRaidenApi, BigInteger.ZERO, balance))
.flatMap(
bdsChannel -> bdsMicroRaidenApi.listAllChannels(Address.from(senderECKey.getAddress()),
false)
.flatMapIterable(ListAllChannelsResponse::getResult)
.map(ListAllChannelsResponse.Result::getBlock)
.contains(bdsChannel.getOpenBlockNumber()
.intValue())
.doOnSuccess(aBoolean -> {
if (!aBoolean) {
throw new RuntimeException();
}
})
.retry()
.map(aBoolean -> bdsChannel));
}
内容来源于网络,如有侵权,请联系作者删除!