Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ public static void showWhile(Future<?> future) {
} else {
Integer busyId = setBusyCursor(display);
try {
// Install a timer as a safety net to periodically wake the event loop in case
// the primary wake signal is lost (e.g. due to a native call may fail to wake the polling function).
// That should be short enough to not be noticeable by the user and long
// enough to not burn more CPU time than necessary
int wakeTime = 10;
display.timerExec(wakeTime, new Runnable() {
@Override
public void run() {
if (!future.isDone() && !display.isDisposed()) {
display.timerExec(wakeTime, this);
}
}
});
if (future instanceof CompletionStage<?> stage) {
// let us wake up from sleep once the future is done
stage.handle((nil1, nil2) -> {
Expand All @@ -119,19 +132,6 @@ public static void showWhile(Future<?> future) {
}
return null;
});
} else {
// for plain features we need to use a workaround, we install a timer every
// few ms, that should be short enough to not be noticeable by the user and long
// enough to not burn more CPU time than necessary
int wakeTime = 10;
display.timerExec(wakeTime, new Runnable() {
@Override
public void run() {
if (!future.isDone() && !display.isDisposed()) {
display.timerExec(wakeTime, this);
}
}
});
}
while (!future.isDone() && !display.isDisposed()) {
if (!display.readAndDispatch()) {
Expand Down
Loading