本文整理汇总了Java中java.util.concurrent.CompletionStage.toCompletableFuture方法的典型用法代码示例。如果您正苦于以下问题:Java CompletionStage.toCompletableFuture方法的具体用法?Java CompletionStage.toCompletableFuture怎么用?Java CompletionStage.toCompletableFuture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.CompletionStage
的用法示例。
在下文中一共展示了CompletionStage.toCompletableFuture方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMinimalCompletionStage_toCompletableFuture_normalCompletion
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
/**
* minimalStage.toCompletableFuture() returns a CompletableFuture that
* is completed normally, with the same value, when source is.
*/
public void testMinimalCompletionStage_toCompletableFuture_normalCompletion() {
for (boolean createIncomplete : new boolean[] { true, false })
for (Integer v1 : new Integer[] { 1, null })
{
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage<Integer> minimal = f.minimalCompletionStage();
if (!createIncomplete) assertTrue(f.complete(v1));
CompletableFuture<Integer> g = minimal.toCompletableFuture();
if (createIncomplete) {
checkIncomplete(f);
checkIncomplete(g);
assertTrue(f.complete(v1));
}
checkCompletedNormally(f, v1);
checkCompletedNormally(g, v1);
}}
示例2: testMinimalCompletionStage_toCompletableFuture_exceptionalCompletion
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
/**
* minimalStage.toCompletableFuture() returns a CompletableFuture that
* is completed exceptionally when source is.
*/
public void testMinimalCompletionStage_toCompletableFuture_exceptionalCompletion() {
for (boolean createIncomplete : new boolean[] { true, false })
{
CFException ex = new CFException();
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage<Integer> minimal = f.minimalCompletionStage();
if (!createIncomplete) f.completeExceptionally(ex);
CompletableFuture<Integer> g = minimal.toCompletableFuture();
if (createIncomplete) {
checkIncomplete(f);
checkIncomplete(g);
f.completeExceptionally(ex);
}
checkCompletedExceptionally(f, ex);
checkCompletedWithWrappedException(g, ex);
}}
示例3: assertCauseOf
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
static ThrowableSubject assertCauseOf(
Class<? extends Throwable> exceptionType, CompletionStage<?> stage) {
CompletableFuture<?> future = stage.toCompletableFuture();
Throwable thrown = Assertions.assertThrows(exceptionType, future::get);
assertThat(future.isDone()).isTrue();
assertThat(future.isCompletedExceptionally()).isTrue();
return assertThat(thrown.getCause());
}
示例4: assertCancelled
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
static CancellationException assertCancelled(CompletionStage<?> stage) {
CompletableFuture<?> future = stage.toCompletableFuture();
assertThat(future.isDone()).isTrue();
assertThat(future.isCompletedExceptionally()).isTrue();
CancellationException cancelled = assertThrows(CancellationException.class, future::get);
assertThat(future.isCancelled()).isTrue();
return cancelled;
}
示例5: biApplyStage
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
private <U,V> CompletableFuture<V> biApplyStage(
Executor e, CompletionStage<U> o,
BiFunction<? super T,? super U,? extends V> f) {
CompletableFuture<U> b;
if (f == null || (b = o.toCompletableFuture()) == null)
throw new NullPointerException();
CompletableFuture<V> d = new CompletableFuture<V>();
if (e != null || !d.biApply(this, b, f, null)) {
BiApply<T,U,V> c = new BiApply<T,U,V>(e, d, this, b, f);
bipush(b, c);
c.tryFire(SYNC);
}
return d;
}
示例6: biAcceptStage
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
private <U> CompletableFuture<Void> biAcceptStage(
Executor e, CompletionStage<U> o,
BiConsumer<? super T,? super U> f) {
CompletableFuture<U> b;
if (f == null || (b = o.toCompletableFuture()) == null)
throw new NullPointerException();
CompletableFuture<Void> d = new CompletableFuture<Void>();
if (e != null || !d.biAccept(this, b, f, null)) {
BiAccept<T,U> c = new BiAccept<T,U>(e, d, this, b, f);
bipush(b, c);
c.tryFire(SYNC);
}
return d;
}
示例7: biRunStage
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
private CompletableFuture<Void> biRunStage(Executor e, CompletionStage<?> o,
Runnable f) {
CompletableFuture<?> b;
if (f == null || (b = o.toCompletableFuture()) == null)
throw new NullPointerException();
CompletableFuture<Void> d = new CompletableFuture<Void>();
if (e != null || !d.biRun(this, b, f, null)) {
BiRun<T,?> c = new BiRun<>(e, d, this, b, f);
bipush(b, c);
c.tryFire(SYNC);
}
return d;
}
示例8: orApplyStage
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
private <U extends T,V> CompletableFuture<V> orApplyStage(
Executor e, CompletionStage<U> o,
Function<? super T, ? extends V> f) {
CompletableFuture<U> b;
if (f == null || (b = o.toCompletableFuture()) == null)
throw new NullPointerException();
CompletableFuture<V> d = new CompletableFuture<V>();
if (e != null || !d.orApply(this, b, f, null)) {
OrApply<T,U,V> c = new OrApply<T,U,V>(e, d, this, b, f);
orpush(b, c);
c.tryFire(SYNC);
}
return d;
}
示例9: orAcceptStage
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
private <U extends T> CompletableFuture<Void> orAcceptStage(
Executor e, CompletionStage<U> o, Consumer<? super T> f) {
CompletableFuture<U> b;
if (f == null || (b = o.toCompletableFuture()) == null)
throw new NullPointerException();
CompletableFuture<Void> d = new CompletableFuture<Void>();
if (e != null || !d.orAccept(this, b, f, null)) {
OrAccept<T,U> c = new OrAccept<T,U>(e, d, this, b, f);
orpush(b, c);
c.tryFire(SYNC);
}
return d;
}
示例10: orRunStage
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
private CompletableFuture<Void> orRunStage(Executor e, CompletionStage<?> o,
Runnable f) {
CompletableFuture<?> b;
if (f == null || (b = o.toCompletableFuture()) == null)
throw new NullPointerException();
CompletableFuture<Void> d = new CompletableFuture<Void>();
if (e != null || !d.orRun(this, b, f, null)) {
OrRun<T,?> c = new OrRun<>(e, d, this, b, f);
orpush(b, c);
c.tryFire(SYNC);
}
return d;
}
示例11: testMinimalCompletionStage_toCompletableFuture_mutable
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
/**
* minimalStage.toCompletableFuture() gives mutable CompletableFuture
*/
public void testMinimalCompletionStage_toCompletableFuture_mutable() {
for (Integer v1 : new Integer[] { 1, null })
{
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage minimal = f.minimalCompletionStage();
CompletableFuture<Integer> g = minimal.toCompletableFuture();
assertTrue(g.complete(v1));
checkCompletedNormally(g, v1);
checkIncomplete(f);
checkIncomplete(minimal.toCompletableFuture());
}}
示例12: CompletableToListenableFutureAdapter
import java.util.concurrent.CompletionStage; //导入方法依赖的package包/类
/**
* Create a new adapter for the given {@link CompletionStage}.
*
* @since 4.3.7
*/
public CompletableToListenableFutureAdapter(CompletionStage<T> completionStage) {
this(completionStage.toCompletableFuture());
}