From 8ec6c05c6b21b561ad715cd6f280bd3b590b91fc Mon Sep 17 00:00:00 2001 From: Sean Gilligan Date: Sat, 5 Mar 2022 10:30:28 -0800 Subject: [PATCH] Threading: replace CountdownLatch with CompletableFuture --- core/src/main/java/org/bitcoinj/utils/Threading.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/utils/Threading.java b/core/src/main/java/org/bitcoinj/utils/Threading.java index 5a11c4cbb..e3f73fb0c 100644 --- a/core/src/main/java/org/bitcoinj/utils/Threading.java +++ b/core/src/main/java/org/bitcoinj/utils/Threading.java @@ -59,13 +59,15 @@ public class Threading { * Put a dummy task into the queue and wait for it to be run. Because it's single threaded, this means all * tasks submitted before this point are now completed. Usually you won't want to use this method - it's a * convenience primarily used in unit testing. If you want to wait for an event to be called the right thing - * to do is usually to create a {@link com.google.common.util.concurrent.SettableFuture} and then call set - * on it. You can then either block on that future, compose it, add listeners to it and so on. + * to do is usually to create a {@link CompletableFuture} and then call {@link CompletableFuture#complete(Object)} + * on it. For example: + *
{@code
+     * CompletableFuture f = CompletableFuture.supplyAsync(() -> event, USER_THREAD)
+     * }
+ * You can then either block on that future, compose it, add listeners to it and so on. */ public static void waitForUserCode() { - final CountDownLatch latch = new CountDownLatch(1); - USER_THREAD.execute(() -> latch.countDown()); - Uninterruptibles.awaitUninterruptibly(latch); + CompletableFuture.runAsync(() -> {}, USER_THREAD).join(); } /**