-
Notifications
You must be signed in to change notification settings - Fork 184
Add getContentsAsync methods to Clipboard #2650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add getContentsAsync methods to Clipboard #2650
Conversation
b2a899f
to
1987581
Compare
Test Results 115 files 115 suites 11m 37s ⏱️ Results for commit 3420711. ♻️ This comment has been updated with latest results. |
One aspect I am unsure of is the naming here. We can't simply overload Am I overthinking this, is |
1987581
to
6197d4a
Compare
In my opinion, thinking about that name is definitely valuable. It might be mistaken as "I just have to wait long enough for the contents to be available" (as it would be the case with the referenced concurrent Java API using an |
Great. Thanks @HeikoKlare for having a look and sharing your thoughts here. I'll leave this open a little bit longer in case anyone else has thoughts or concerns. |
I'm also fine with that name, an alternative I often use in this case is simply omit the "get" and use the "shortform" what is the In any case every java developer should be aware that joining a feature is always a bad thing and a source of code-smell. |
I am pretty fond of this too, especially when making new API these days. I like "ProcessBuilder" in Java in this way. |
6197d4a
to
54fcebd
Compare
I believe this is ready to go . Only request from my side is to add a reference in getContents javadoc refering to the new method and guiding users to choose it. |
Obtaining data from the clipboard is fundamentally an asynchronous operation, the event loop, at least at the OS level, needs to run for the data to become available. This PR proposes new API that provides asynchronous equivalents of getContents methods called getContentsAsync that return CompleteableFutures. This new API will allow SWT API consumers to interact better with the clipboard when the OS (window system) API is actually implemented in an asynchronous manner. GTK3 and cocoa provides API that spins the event loop as needed so that a synchronous looking API can be provided to the user of the API. For example, in SWT we use gtk_clipboard_wait_for_contents which spins the loop in the GTK library itself [here](https://gitlab.gnome.org/GNOME/gtk/-/blob/716458e86a222f43e64f7a4feda37749f3469ee4/gtk/gtkclipboard.c#L1436) GTK4 does not provide such an API and leaves it to the user of the API to spin the event loop. Win32 is somewhat of a hybrid. The API appears synchronous, but SWT needs to spin in a couple of places, such as [getData](https://github.com/eclipse-platform/eclipse.platform.swt/blob/63e8925dc77db3b93ef521dc6cf2bd6ded7bab64/bundles/org.eclipse.swt/Eclipse%20SWT%20Drag%20and%20Drop/win32/org/eclipse/swt/dnd/Transfer.java#L46) Part of eclipse-platform#2598 and eclipse-platform#2126
54fcebd
to
3420711
Compare
Done: See diffs here |
Obtaining data from the clipboard is fundamentally an asynchronous operation, the event loop, at least at the OS level, needs to run for the data to become available.
This PR proposes new API that provides asynchronous equivalents of getContents methods called getContentsAsync that return CompleteableFutures.
This new API will allow SWT API consumers to interact better with the clipboard when the OS (window system) API is actually implemented in an asynchronous manner.
GTK3 and cocoa provides API that spins the event loop as needed so that a synchronous looking API can be provided to the user of the API. For example, in SWT we use gtk_clipboard_wait_for_contents which spins the loop in the GTK library itself
here
GTK4 does not provide such an API and leaves it to the user of the API to spin the event loop.
Win32 is somewhat of a hybrid. The API appears synchronous, but SWT needs to spin in a couple of places, such as
getData
Part of #2598 and #2126