本文整理汇总了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);
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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());
}