< prev index next >
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/MinimalFuture.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 137,147 ****
return (MinimalFuture<T>)
copy.thenApplyAsync(Function.identity(), executor);
}
}
! public <U> MinimalFuture<U> newIncompleteFuture() {
return new MinimalFuture<>();
}
@Override
public void obtrudeValue(T value) {
--- 137,147 ----
return (MinimalFuture<T>)
copy.thenApplyAsync(Function.identity(), executor);
}
}
! public static <U> MinimalFuture<U> newMinimalFuture() {
return new MinimalFuture<>();
}
@Override
public void obtrudeValue(T value) {
*** 155,160 ****
--- 155,174 ----
@Override
public String toString() {
return super.toString() + " (id=" + id +")";
}
+
+ public static <U> MinimalFuture<U> of(CompletionStage<U> stage) {
+ MinimalFuture<U> cf = newMinimalFuture();
+ stage.whenComplete((r,t) -> complete(cf, r, t));
+ return cf;
+ }
+
+ private static <U> void complete(CompletableFuture<U> cf, U result, Throwable t) {
+ if (t == null) {
+ cf.complete(result);
+ } else {
+ cf.completeExceptionally(t);
+ }
+ }
}
< prev index next >