Skip to content

Commit

Permalink
implement ManagedCompletableFuture few more asynch methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aubi authored and breakponchito committed May 13, 2022
1 parent 39b723b commit 81bb0b5
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public <U> CompletableFuture<U> newIncompleteFuture() {

@Override
public <U> CompletableFuture<U> thenApply(Function<? super T, ? extends U> fn) {
return super.thenApply(fn);
return super.thenApply(executor.getContextService().contextualFunction(fn));
}

public static <T> CompletableFuture<T> supplyAsync(Supplier<T> supplier, ManagedExecutorService executor) {
Expand All @@ -89,12 +89,32 @@ public static <T> CompletableFuture<T> supplyAsync(Supplier<T> supplier, Managed
return managedFuture;
}

@Override
public <U> CompletableFuture<U> thenApplyAsync(Function<? super T, ? extends U> fn) {
return thenApplyAsync(fn, executor);
}

@Override
public <U> CompletableFuture<U> thenApplyAsync(Function<? super T, ? extends U> fn, Executor executor) {
// FIXME: implement correctly
return super.thenApplyAsync(fn, executor);
}

@Override
public <U, V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) {
return thenCombineAsync(other, executor.getContextService().contextualFunction(fn), executor);
}

@Override
public <U, V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) {
return super.thenCombineAsync(other, fn, executor);
}

@Override
public <U> CompletableFuture<U> handleAsync(BiFunction<? super T, Throwable, ? extends U> fn) {
// FIXME: implement correctly
return super.handleAsync(executor.getContextService().contextualFunction(fn));
}

@Override
public <U, V> CompletableFuture<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) {
return super.thenCombine(other, executor.getContextService().contextualFunction(fn));
Expand All @@ -117,8 +137,7 @@ public static <T> CompletableFuture<T> copy(CompletableFuture<T> future, Managed
}

public static <T> CompletionStage<T> copy(CompletionStage<T> stage, ManagedExecutorService executor) {
CompletableFuture<T> future = (CompletableFuture<T>) stage;
return future.copy();
return stage.thenApply(Function.identity());
}

public static <U> CompletableFuture<U> failedFuture(Throwable ex, ManagedExecutorService executor) {
Expand Down

0 comments on commit 81bb0b5

Please sign in to comment.