Bug 571421 - [UISynchronize] provide a more advanced Future-based API to access the UI system
Summary: [UISynchronize] provide a more advanced Future-based API to access the UI system
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.20   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 563459
Blocks:
  Show dependency tree
 
Reported: 2021-02-23 00:05 EST by Christoph Laeubrich CLA
Modified: 2021-02-23 01:34 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Laeubrich CLA 2021-02-23 00:05:29 EST
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.