mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-23 03:59:36 +00:00
fix ThreadUtils.await() blocking on exception
This commit is contained in:
parent
847e9e8701
commit
11c8b05f45
1 changed files with 13 additions and 2 deletions
|
@ -48,14 +48,25 @@ public class ThreadUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Awaits execution of the given command, but does not throw its exception.
|
||||||
|
*
|
||||||
|
* @param command the command to execute
|
||||||
|
* @param threadId the thread id
|
||||||
|
*/
|
||||||
public static void await(Runnable command, String threadId) {
|
public static void await(Runnable command, String threadId) {
|
||||||
if (isCurrentThread(Thread.currentThread(), threadId)) {
|
if (isCurrentThread(Thread.currentThread(), threadId)) {
|
||||||
command.run();
|
command.run();
|
||||||
} else {
|
} else {
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
execute(() -> {
|
execute(() -> {
|
||||||
|
try {
|
||||||
command.run();
|
command.run();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
}
|
||||||
}, threadId);
|
}, threadId);
|
||||||
try {
|
try {
|
||||||
latch.await();
|
latch.await();
|
||||||
|
|
Loading…
Reference in a new issue