mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-20 07:20:41 -04:00
move processing off UserThread for smoother experience
This commit is contained in:
parent
ba9a9a3dcc
commit
e6775f3b58
16 changed files with 276 additions and 215 deletions
|
@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.time.Duration;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -59,6 +60,19 @@ public class UserThread {
|
|||
UserThread.executor.execute(command);
|
||||
}
|
||||
|
||||
public static void await(Runnable command) {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
executor.execute(() -> {
|
||||
command.run();
|
||||
latch.countDown();
|
||||
});
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Prefer FxTimer if a delay is needed in a JavaFx class (gui module)
|
||||
public static Timer runAfterRandomDelay(Runnable runnable, long minDelayInSec, long maxDelayInSec) {
|
||||
return UserThread.runAfterRandomDelay(runnable, minDelayInSec, maxDelayInSec, TimeUnit.SECONDS);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue