本文整理匯總了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());
}