3925 |
|
Monad.plus(godot, Monad.unit(5L))); |
3926 |
|
} |
3927 |
|
|
3928 |
+ |
/** |
3929 |
+ |
* A single CompletableFuture with many dependents. |
3930 |
+ |
*/ |
3931 |
+ |
public void testManyDependents() throws Throwable { |
3932 |
+ |
final int n = 10_000; |
3933 |
+ |
final CompletableFuture<Void> head = new CompletableFuture<>(); |
3934 |
+ |
final CompletableFuture<Void> incomplete = new CompletableFuture<>(); |
3935 |
+ |
final CompletableFuture<Void> complete = CompletableFuture.completedFuture((Void)null); |
3936 |
+ |
final AtomicInteger count = new AtomicInteger(0); |
3937 |
+ |
for (int i = 0; i < n; i++) { |
3938 |
+ |
head.thenRun(() -> count.getAndIncrement()); |
3939 |
+ |
head.thenAccept((x) -> count.getAndIncrement()); |
3940 |
+ |
head.thenApply((x) -> count.getAndIncrement()); |
3941 |
+ |
head.runAfterBoth(complete, () -> count.getAndIncrement()); |
3942 |
+ |
head.thenAcceptBoth(complete, (x, y) -> count.getAndIncrement()); |
3943 |
+ |
head.thenCombine(complete, (x, y) -> count.getAndIncrement()); |
3944 |
+ |
head.runAfterEither(incomplete, () -> count.getAndIncrement()); |
3945 |
+ |
head.acceptEither(incomplete, (x) -> count.getAndIncrement()); |
3946 |
+ |
head.applyToEither(incomplete, (x) -> count.getAndIncrement()); |
3947 |
+ |
} |
3948 |
+ |
head.complete(null); |
3949 |
+ |
assertEquals(9 * n, count.get()); |
3950 |
+ |
} |
3951 |
+ |
|
3952 |
|
// static <U> U join(CompletionStage<U> stage) { |
3953 |
|
// CompletableFuture<U> f = new CompletableFuture<>(); |
3954 |
|
// stage.whenComplete((v, ex) -> { |