com.linkedin.parseq.Task.transform()方法的使用及代码示例

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

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

Task.transform介绍

[英]Equivalent to transform("transform", func).
[中]相当于变换(“变换”,func)。

代码示例

代码示例来源:origin: linkedin/parseq

/**
 * Equivalent to {@code transform("transform", func)}.
 * @see #transform(String, Function1)
 */
default <R> Task<R> transform(final Function1<Try<T>, Try<R>> func) {
 return transform("transform: " + _taskDescriptor.getDescription(func.getClass().getName()), func);
}

代码示例来源:origin: linkedin/parseq

private <T> Task<Response<T>> withD2Timeout(final Task<Response<T>> task, ConfigValue<Long> timeout) {
 String srcDesc = timeout.getSource().map(src -> " src: " + src).orElse("");
 String timeoutTaskName = "withTimeout " + timeout.getValue().intValue() + TimeUnitHelper.toString(TimeUnit.MILLISECONDS)
   + srcDesc;
 // make sure that we throw the same exception to maintain backward compatibility with current withTimeout implementation.
 return task.transform(timeoutTaskName, (Try<Response<T>> tryGet) -> {
  if (tryGet.isFailed() && tryGet.getError() instanceof TimeoutException) {
   String timeoutExceptionMessage = "task: '" + task.getName() + "' " + timeoutTaskName;
   return Failure.of(Exceptions.timeoutException(timeoutExceptionMessage));
  } else {
   return tryGet;
  }
 });
}

代码示例来源:origin: linkedin/parseq

@Test
public void testTransformFailureToFailure() {
 Task<String> failure = getFailureTask();
 final Exception failureReason = new Exception();
 Task<String> transformed = failure.transform(tryT -> Failure.of(failureReason));
 try {
  runAndWait("AbstractTaskTest.testTransformFailureToFailure", transformed);
  fail("should have failed");
 } catch (Exception ex) {
  assertTrue(transformed.isFailed());
 }
 assertSame(transformed.getError(), failureReason);
}

代码示例来源:origin: linkedin/parseq

@Test
public void testTransformFailureToSuccess() {
 Task<String> failure = getFailureTask();
 Task<String> transformed = failure.transform(tryT -> Success.of(tryT.getError().toString() + "transformed"));
 runAndWait("AbstractTaskTest.testTransformFailureToSuccess", transformed);
 assertEquals(transformed.get(), failure.getError().toString() + "transformed");
}

代码示例来源:origin: linkedin/parseq

@Test
public void testTransformSuccessToFailure() {
 Task<String> success = getSuccessTask();
 final Exception failureReason = new Exception();
 Task<String> transformed = success.transform(tryT -> Failure.of(failureReason));
 try {
  runAndWait("AbstractTaskTest.testTransformSuccessToSuccess", transformed);
  fail("should have failed");
 } catch (Exception ex) {
  assertTrue(transformed.isFailed());
 }
 assertSame(transformed.getError(), failureReason);
}

代码示例来源:origin: linkedin/parseq

@Test
public void testTransformSuccessToSuccess() {
 Task<String> success = getSuccessTask();
 Task<String> transformed = success.transform(tryT -> Success.of(tryT.get() + "transformed"));
 runAndWait("AbstractTaskTest.testTransformSuccessToSuccess", transformed);
 assertEquals(transformed.get(), success.get() + "transformed");
}

代码示例来源:origin: com.linkedin.parseq/parseq

/**
 * Equivalent to {@code transform("transform", func)}.
 * @see #transform(String, Function1)
 */
default <R> Task<R> transform(final Function1<Try<T>, Try<R>> func) {
 return transform("transform: " + _taskDescriptor.getDescription(func.getClass().getName()), func);
}

代码示例来源:origin: com.linkedin.parseq/parseq-tracevis-server

return buildTask.transform("result", result -> {
 Integer status = null;
 String content = null;

相关文章