reactor.core.publisher.Mono.onErrorContinue()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(2.6k)|赞(0)|评价(0)|浏览(267)

本文整理了Java中reactor.core.publisher.Mono.onErrorContinue()方法的一些代码示例,展示了Mono.onErrorContinue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.onErrorContinue()方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:onErrorContinue

Mono.onErrorContinue介绍

[英]Let compatible operators upstream recover from errors by dropping the incriminating element from the sequence and continuing with subsequent elements. Only errors matching the specified type are recovered from. The recovered error and associated value are notified via the provided BiConsumer.

Note that this error handling mode is not necessarily implemented by all operators (look for the Error Mode Support javadoc section to find operators that support it).
[中]

代码示例

代码示例来源:origin: reactor/reactor-core

/**
 * Let compatible operators <strong>upstream</strong> recover from errors by dropping the
 * incriminating element from the sequence and continuing with subsequent elements.
 * Only errors matching the specified {@code type} are recovered from.
 * The recovered error and associated value are notified via the provided {@link BiConsumer}.
 * <p>
 * Note that this error handling mode is not necessarily implemented by all operators
 * (look for the {@code Error Mode Support} javadoc section to find operators that
 * support it).
 *
 * @return a {@link Mono} that attempts to continue processing on some errors.
 */
public final <E extends Throwable> Mono<T> onErrorContinue(Class<E> type, BiConsumer<Throwable, Object> errorConsumer) {
  return onErrorContinue(type::isInstance, errorConsumer);
}

代码示例来源:origin: reactor/reactor-core

@Test
public void errorContinueOnMonoReduction() {
  AtomicReference<Tuple2<Class, Object>> ref = new AtomicReference<>();
  StepVerifier.create(Flux.just(1, 0, 2)
              .map(v -> 100 / v)
              .reduce((a, b) -> a + b)
              .onErrorContinue(ArithmeticException.class, (t, v) -> ref.set(Tuples.of(t.getClass(), v))))
        .expectNext(100 + 50)
        .verifyComplete();
  Assertions.assertThat(ref).hasValue(Tuples.of(ArithmeticException.class, 0));
}

代码示例来源:origin: io.projectreactor/reactor-core

/**
 * Let compatible operators <strong>upstream</strong> recover from errors by dropping the
 * incriminating element from the sequence and continuing with subsequent elements.
 * Only errors matching the specified {@code type} are recovered from.
 * The recovered error and associated value are notified via the provided {@link BiConsumer}.
 * <p>
 * Note that this error handling mode is not necessarily implemented by all operators
 * (look for the {@code Error Mode Support} javadoc section to find operators that
 * support it).
 *
 * @return a {@link Mono} that attempts to continue processing on some errors.
 */
public final <E extends Throwable> Mono<T> onErrorContinue(Class<E> type, BiConsumer<Throwable, Object> errorConsumer) {
  return onErrorContinue(type::isInstance, errorConsumer);
}

相关文章

Mono类方法