Community
Participate
Working Groups
This is a followup of Bug 563459 where it has shown to better postpone some changes to the next release for getting a clearer and better understanding on the overall API design. Summary: -------- Currently UISynchronize just provides methods to either sync or async exec an executable. While this works for simple cases, both have drawbacks when used in more advanced scenarios: - sync exec is prone to deadlocks if e.g. called in succession from the ui thread, as one can't be sure if code is called from UI thread or not additional checks have to be performed prior to every call. - sync/async are both offer no way to pass back a value to the caller e.g. from a function call - due to the runnable-interface contract, only runtime exceptions are passed back to the caller, checked exceptions has either be wrapped or handled in the ui thread - there is no lightweight way to give feedback to the user that something is running (e.g. show a progress wheel) Proposal: --------- The proposal is to offer a set of function that are using the CompletableFuture API to be called from any thread. The code will take care if the action can take place immediately (e.g. already on the UI thread) or need to be scheduled for execution in the UI thread. The caller can the wait, be notified or even cancel the request through the CompletableFuture. Beside that variant should exits that show a small progresswheel and accept a Callable to account for return values and checked exceptions. A first draft can be found in the following gerrit: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/176516 Things to consider: ------------------- It might be worth to decide if parts of the API could be made available in the SWT project instead as part of the Display class. The (Device)UISynchronize can then simply delegate to these methods and it could be used in pure SWT applications or where E4 is not available.
Maybe it is worth to have a look at the implementations in e(fx)clipse that provides such kind of API for quite a while: https://git.eclipse.org/c/efxclipse/org.eclipse.efxclipse.git/tree/bundles/runtime/org.eclipse.fx.core/src/org/eclipse/fx/core/ThreadSynchronize.java?id=12e51df1e48ad9d889b9fb64635b5fa23af5d065 https://git.eclipse.org/c/efxclipse/org.eclipse.efxclipse.git/tree/bundles/runtime/org.eclipse.fx.ui.di.interopt/src/org/eclipse/fx/ui/di/interopt/UISynchronizeImpl.java?id=12e51df1e48ad9d889b9fb64635b5fa23af5d065