Added applySequenceAsync to CompletableFuture utils
This commit is contained in:
parent
27ec2c3a40
commit
ce9fc49cb1
@ -12,6 +12,7 @@ import java.util.TreeSet;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -175,4 +176,12 @@ public class CompletableFutureUtils {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> CompletableFuture<T> applySequenceAsync(T initialValue, Collection<Function<T, CompletableFuture<T>>> collection, ExecutorService executorService) {
|
||||
var result = CompletableFuture.completedFuture(initialValue);
|
||||
for (Function<T, CompletableFuture<T>> item : collection) {
|
||||
result = result.thenComposeAsync(item, executorService);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user