Skip to content

Conversation

jonahgraham
Copy link
Contributor

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

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
Copy link
Contributor

Test Results

  115 files  ±0    115 suites  ±0   12m 3s ⏱️ -25s
4 555 tests +1  4 539 ✅ +1  16 💤 ±0  0 ❌ ±0 
  311 runs  ±0    308 ✅ ±0   3 💤 ±0  0 ❌ ±0 

Results for commit 1987581. ± Comparison against base commit d2de8e3.

@jonahgraham
Copy link
Contributor Author

One aspect I am unsure of is the naming here.

We can't simply overload getContents because the only difference in the new method is the return type. But in java.util.concurrent it seems generally the Async suffixed methods imply running in a separate (asynchronous) thread.

Am I overthinking this, is getContentsAsync a good name? @laeubi any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant