io.vavr.control.Try.andThen()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.0k)|赞(0)|评价(0)|浏览(84)

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

Try.andThen介绍

[英]Shortcut for andThenTry(runnable::run), see #andThenTry(CheckedRunnable).
[中]第条记录(runnable::run)的快捷方式,请参见#第条记录(CheckedRunnable)。

代码示例

代码示例来源:origin: resilience4j/resilience4j

private V computeAndPut(K cacheKey, CheckedFunction0<V> supplier) {
  return Try.of(supplier)
      .andThen(value -> putValueIntoCache(cacheKey, value))
    .get();
}

代码示例来源:origin: resilience4j/resilience4j

@Test
public void decorateConsumer() throws Exception {
  Consumer<Integer> consumer = mock(Consumer.class);
  Consumer<Integer> decorated = RateLimiter.decorateConsumer(limit, consumer);
  when(limit.getPermission(config.getTimeoutDuration()))
    .thenReturn(false);
  Try<Integer> decoratedConsumerResult = Try.success(1).andThen(decorated);
  then(decoratedConsumerResult.isFailure()).isTrue();
  then(decoratedConsumerResult.getCause()).isInstanceOf(RequestNotPermitted.class);
  verify(consumer, never()).accept(any());
  when(limit.getPermission(config.getTimeoutDuration()))
    .thenReturn(true);
  Try secondConsumerResult = Try.success(1).andThen(decorated);
  then(secondConsumerResult.isSuccess()).isTrue();
  verify(consumer, times(1)).accept(1);
}

代码示例来源:origin: resilience4j/resilience4j

@Test
public void decorateRunnable() throws Exception {
  Runnable runnable = mock(Runnable.class);
  Runnable decorated = RateLimiter.decorateRunnable(limit, runnable);
  when(limit.getPermission(config.getTimeoutDuration()))
    .thenReturn(false);
  Try decoratedRunnableResult = Try.success(decorated).andThen(Runnable::run);
  then(decoratedRunnableResult.isFailure()).isTrue();
  then(decoratedRunnableResult.getCause()).isInstanceOf(RequestNotPermitted.class);
  verify(runnable, never()).run();
  when(limit.getPermission(config.getTimeoutDuration()))
    .thenReturn(true);
  Try secondRunnableResult = Try.success(decorated).andThen(Runnable::run);
  then(secondRunnableResult.isSuccess()).isTrue();
  verify(runnable, times(1)).run();
}

代码示例来源:origin: io.github.resilience4j/resilience4j-cache

private V computeAndPut(K cacheKey, CheckedFunction0<V> supplier) {
  return Try.of(supplier)
      .andThen(value -> putValueIntoCache(cacheKey, value))
    .get();
}

代码示例来源:origin: Tristan971/Lyrebird

/**
 * Called when the user requests the adding of a new account.
 */
private void handleNewSessionRequest() {
  easyFxml.loadNode(Screen.LOGIN_VIEW)
      .getNode()
      .map(loginScreen -> Stages.stageOf("Add new account", loginScreen))
      .andThen(Stages::scheduleDisplaying);
}

代码示例来源:origin: Tristan971/Lyrebird

/**
 * Asynchronously loads the last tweets available
 */
public void refresh() {
  CompletableFuture.runAsync(() -> {
    if (sessionManager.getCurrentTwitter().getOrElse((Twitter) null) == null) {
      return;
    }
    getLocalLogger().debug("Requesting last tweets in timeline.");
    sessionManager.getCurrentTwitter()
           .mapTry(this::initialLoad)
           .onSuccess(this::addTweets)
           .onFailure(err -> getLocalLogger().error("Could not refresh!", err))
           .andThen(() -> isFirstCall.set(false));
  });
}

代码示例来源:origin: Tristan971/Lyrebird

private void displayApplicationAuthor() {
  applicationAuthorProfileLink.setOnAction(e -> userDetailsService.openUserDetails("_tristan971_"));
  userDetailsService.findUser("_tristan971_")
           .map(User::getProfileImageURLHttps)
           .map(cachedMedia::loadImage)
           .onSuccess(applicationAuthorProfilePicture::setImage)
           .andThen(() -> applicationAuthorProfilePicture.setClip(Clipping.getCircleClip(16.0)));
}

代码示例来源:origin: Tristan971/Lyrebird

/**
 * Pre-formats a status' text content.
 *
 * @param status The status whose content we have to format
 */
private void loadTextIntoTextFlow(final Status status) {
  tweetContent.getChildren().clear();
  final FxmlLoadResult<Pane, TweetContentPaneController> result = easyFxml.loadNode(
      FxComponent.TWEET_CONTENT_PANE,
      Pane.class,
      TweetContentPaneController.class
  );
  result.afterControllerLoaded(tcpc -> tcpc.setStatusProp(status))
     .getNode()
     .peek(pane -> VBox.setVgrow(pane, Priority.ALWAYS))
     .recover(ExceptionHandler::fromThrowable)
     .andThen(tweetContent.getChildren()::add);
}

相关文章