當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。