Skip to content

Commit e93c1b1

Browse files
committed
Ensure terminal async runnables are run asynchronously
Fixes #2155
1 parent 00bf88d commit e93c1b1

File tree

1 file changed

+15
-6
lines changed
  • terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal

1 file changed

+15
-6
lines changed

terminal/bundles/org.eclipse.terminal.view.ui/src/org/eclipse/terminal/view/ui/internal/TerminalService.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,21 @@ protected final CompletableFuture<?> executeServiceOperation(final Map<String, O
193193

194194
private CompletableFuture<?> executeServiceOperation(final TerminalServiceRunnable runnable, TerminalViewId tvid,
195195
final String title, final ITerminalConnector connector, final Object data) {
196-
// Execute the operation
197-
if (runnable.isExecuteAsync()) {
198-
return CompletableFuture.supplyAsync(() -> runnable.run(tvid, title, connector, data),
199-
Display.getDefault());
200-
} else {
201-
return CompletableFuture.completedFuture(runnable.run(tvid, title, connector, data));
196+
try { // Execute the operation
197+
if (runnable.isExecuteAsync()) {
198+
return CompletableFuture.supplyAsync(() -> runnable.run(tvid, title, connector, data),
199+
/*
200+
* A special executor is used here because the default Display executor will
201+
* do a syncExec here if called from the UI thread, but isExecuteAsync is true so we
202+
* must run async on the UI thread.
203+
*/
204+
Display.getDefault()::asyncExec);
205+
206+
} else {
207+
return CompletableFuture.completedFuture(runnable.run(tvid, title, connector, data));
208+
}
209+
} catch (RuntimeException e) {
210+
return CompletableFuture.failedFuture(e);
202211
}
203212
}
204213

0 commit comments

Comments
 (0)