File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
src/main/java/net/tascalate/concurrent Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 1616package net .tascalate .concurrent ;
1717
1818import java .util .concurrent .CompletionStage ;
19+ import java .util .concurrent .ExecutionException ;
1920import java .util .concurrent .Executor ;
2021import java .util .concurrent .Future ;
2122import java .util .function .BiConsumer ;
2223import java .util .function .BiFunction ;
2324import java .util .function .Consumer ;
2425import java .util .function .Function ;
26+ import java .util .function .Supplier ;
2527
2628/**
2729 * <p>{@link Promise} is a combination of the {@link CompletionStage} and {@link Future} contracts.
3436 * a type of the successfully resolved promise value
3537 */
3638public interface Promise <T > extends Future <T >, CompletionStage <T > {
39+
40+ default public T getNow (T valueIfAbsent ) throws InterruptedException , ExecutionException {
41+ return getNow (() -> valueIfAbsent );
42+ }
43+
44+ default public T getNow (Supplier <T > valueIfAbsent ) throws InterruptedException , ExecutionException {
45+ if (isDone ()) {
46+ return get ();
47+ } else {
48+ return valueIfAbsent .get ();
49+ }
50+ }
3751
3852 public <U > Promise <U > thenApply (Function <? super T , ? extends U > fn );
3953
You can’t perform that action at this time.
0 commit comments