mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-19 05:33:44 +01:00
Threading: replace CountdownLatch with CompletableFuture
This commit is contained in:
parent
11d676d103
commit
8ec6c05c6b
@ -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:
|
||||
* <pre>{@code
|
||||
* CompletableFuture f = CompletableFuture.supplyAsync(() -> event, USER_THREAD)
|
||||
* }</pre>
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user