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

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

本文整理了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

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

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

  1. @Test
  2. public void decorateConsumer() throws Exception {
  3. Consumer<Integer> consumer = mock(Consumer.class);
  4. Consumer<Integer> decorated = RateLimiter.decorateConsumer(limit, consumer);
  5. when(limit.getPermission(config.getTimeoutDuration()))
  6. .thenReturn(false);
  7. Try<Integer> decoratedConsumerResult = Try.success(1).andThen(decorated);
  8. then(decoratedConsumerResult.isFailure()).isTrue();
  9. then(decoratedConsumerResult.getCause()).isInstanceOf(RequestNotPermitted.class);
  10. verify(consumer, never()).accept(any());
  11. when(limit.getPermission(config.getTimeoutDuration()))
  12. .thenReturn(true);
  13. Try secondConsumerResult = Try.success(1).andThen(decorated);
  14. then(secondConsumerResult.isSuccess()).isTrue();
  15. verify(consumer, times(1)).accept(1);
  16. }

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

  1. @Test
  2. public void decorateRunnable() throws Exception {
  3. Runnable runnable = mock(Runnable.class);
  4. Runnable decorated = RateLimiter.decorateRunnable(limit, runnable);
  5. when(limit.getPermission(config.getTimeoutDuration()))
  6. .thenReturn(false);
  7. Try decoratedRunnableResult = Try.success(decorated).andThen(Runnable::run);
  8. then(decoratedRunnableResult.isFailure()).isTrue();
  9. then(decoratedRunnableResult.getCause()).isInstanceOf(RequestNotPermitted.class);
  10. verify(runnable, never()).run();
  11. when(limit.getPermission(config.getTimeoutDuration()))
  12. .thenReturn(true);
  13. Try secondRunnableResult = Try.success(decorated).andThen(Runnable::run);
  14. then(secondRunnableResult.isSuccess()).isTrue();
  15. verify(runnable, times(1)).run();
  16. }

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

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

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

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

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

  1. /**
  2. * Asynchronously loads the last tweets available
  3. */
  4. public void refresh() {
  5. CompletableFuture.runAsync(() -> {
  6. if (sessionManager.getCurrentTwitter().getOrElse((Twitter) null) == null) {
  7. return;
  8. }
  9. getLocalLogger().debug("Requesting last tweets in timeline.");
  10. sessionManager.getCurrentTwitter()
  11. .mapTry(this::initialLoad)
  12. .onSuccess(this::addTweets)
  13. .onFailure(err -> getLocalLogger().error("Could not refresh!", err))
  14. .andThen(() -> isFirstCall.set(false));
  15. });
  16. }

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

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

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

  1. /**
  2. * Pre-formats a status' text content.
  3. *
  4. * @param status The status whose content we have to format
  5. */
  6. private void loadTextIntoTextFlow(final Status status) {
  7. tweetContent.getChildren().clear();
  8. final FxmlLoadResult<Pane, TweetContentPaneController> result = easyFxml.loadNode(
  9. FxComponent.TWEET_CONTENT_PANE,
  10. Pane.class,
  11. TweetContentPaneController.class
  12. );
  13. result.afterControllerLoaded(tcpc -> tcpc.setStatusProp(status))
  14. .getNode()
  15. .peek(pane -> VBox.setVgrow(pane, Priority.ALWAYS))
  16. .recover(ExceptionHandler::fromThrowable)
  17. .andThen(tweetContent.getChildren()::add);
  18. }

相关文章