Skip to content

Commit 1121211

Browse files
committed
Use timer unconditionally in BusyIndicator.showWhile(Future)
Should prevent hangs like #3044
1 parent 992e08d commit 1121211

File tree

1 file changed

+13
-13
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom

1 file changed

+13
-13
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/BusyIndicator.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ public static void showWhile(Future<?> future) {
106106
} else {
107107
Integer busyId = setBusyCursor(display);
108108
try {
109+
// Install a timer as a safety net to periodically wake the event loop in case
110+
// the primary wake signal is lost (e.g. due to a native call may fail to wake the polling function).
111+
// That should be short enough to not be noticeable by the user and long
112+
// enough to not burn more CPU time than necessary
113+
int wakeTime = 10;
114+
display.timerExec(wakeTime, new Runnable() {
115+
@Override
116+
public void run() {
117+
if (!future.isDone() && !display.isDisposed()) {
118+
display.timerExec(wakeTime, this);
119+
}
120+
}
121+
});
109122
if (future instanceof CompletionStage<?> stage) {
110123
// let us wake up from sleep once the future is done
111124
stage.handle((nil1, nil2) -> {
@@ -119,19 +132,6 @@ public static void showWhile(Future<?> future) {
119132
}
120133
return null;
121134
});
122-
} else {
123-
// for plain features we need to use a workaround, we install a timer every
124-
// few ms, that should be short enough to not be noticeable by the user and long
125-
// enough to not burn more CPU time than necessary
126-
int wakeTime = 10;
127-
display.timerExec(wakeTime, new Runnable() {
128-
@Override
129-
public void run() {
130-
if (!future.isDone() && !display.isDisposed()) {
131-
display.timerExec(wakeTime, this);
132-
}
133-
}
134-
});
135135
}
136136
while (!future.isDone() && !display.isDisposed()) {
137137
if (!display.readAndDispatch()) {

0 commit comments

Comments
 (0)