当前位置: 首页>>代码示例>>Java>>正文


Java CompletableFuture.thenComposeAsync方法代码示例

本文整理汇总了Java中java.util.concurrent.CompletableFuture.thenComposeAsync方法的典型用法代码示例。如果您正苦于以下问题:Java CompletableFuture.thenComposeAsync方法的具体用法?Java CompletableFuture.thenComposeAsync怎么用?Java CompletableFuture.thenComposeAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.CompletableFuture的用法示例。


在下文中一共展示了CompletableFuture.thenComposeAsync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1:

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public <T,U> CompletableFuture<U> thenCompose
    (CompletableFuture<T> f,
     Function<? super T,? extends CompletionStage<U>> a) {
    return f.thenComposeAsync(a);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:CompletableFutureTest.java

示例2: submitCommit

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
CompletableFuture<Integer> submitCommit(
    long offset, int size, Function<UnderConstruction, ReadOnly> converter,
    ExecutorService executor, RaftPeerId id, long index) {
  final Supplier<String> name = () -> "commit(" + getRelativePath() + ", "
      + offset + ", " + size + ") @" + id + ":" + index;
  final CheckedSupplier<Integer, IOException> task = LogUtils.newCheckedSupplier(LOG, () -> {
    if (offset != committedSize) {
      throw new IOException("Offset/size mismatched: offset = "
          + offset + " != committedSize = " + committedSize
          + ", path=" + getRelativePath());
    } else if (committedSize + size > writeSize) {
      throw new IOException("Offset/size mismatched: committed (=" + committedSize
          + ") + size (=" + size + ") > writeSize = " + writeSize);
    }
    committedSize += size;

    if (converter != null) {
      converter.apply(this);
    }
    return size;
  }, name);

  final CompletableFuture<Integer> write = writeFutures.remove(index);
  if (write == null) {
    return JavaUtils.completeExceptionally(
        new IOException(name.get() + " is already committed."));
  }
  return write.thenComposeAsync(writeSize -> {
    Preconditions.assertTrue(size == writeSize);
    return commitQueue.submit(task, executor,
        e -> new IOException("Failed " + task, e));
  }, executor);
}
 
开发者ID:apache,项目名称:incubator-ratis,代码行数:34,代码来源:FileInfo.java

示例3: flatMapConstN

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Benchmark
public String flatMapConstN() throws InterruptedException, ExecutionException {
  CompletableFuture<String> f = constFuture;
  for (int i = 0; i < N.n; i++)
    f = f.thenComposeAsync(flatMapF);
  return f.get();
}
 
开发者ID:traneio,项目名称:future,代码行数:8,代码来源:JavaAsyncFutureBenchmark.java

示例4: flatMapPromise

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Benchmark
public String flatMapPromise() throws InterruptedException, ExecutionException {
  CompletableFuture<String> p = new CompletableFuture<String>();
  p.thenComposeAsync(flatMapF);
  p.complete(string);
  return p.get();
}
 
开发者ID:traneio,项目名称:future,代码行数:8,代码来源:JavaAsyncFutureBenchmark.java

示例5: flatMapPromiseN

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Benchmark
public String flatMapPromiseN() throws InterruptedException, ExecutionException {
  CompletableFuture<String> p = new CompletableFuture<>();
  CompletableFuture<String> f = p;
  for (int i = 0; i < N.n; i++)
    f = f.thenComposeAsync(flatMapF);
  p.complete(string);
  return f.get();
}
 
开发者ID:traneio,项目名称:future,代码行数:10,代码来源:JavaAsyncFutureBenchmark.java

示例6: ThreadExecutor

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public <T,U> CompletableFuture<U> thenCompose
    (CompletableFuture<T> f,
     Function<? super T,? extends CompletionStage<U>> a) {
    return f.thenComposeAsync(a, new ThreadExecutor());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:CompletableFutureTest.java


注:本文中的java.util.concurrent.CompletableFuture.thenComposeAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。