AsyncCallback on client to server rpc calls?


I am currently working on a frontend widget that is using a Vaadin RPC call followed by some logic that needs to happen
the call is finished. While there are the asynchronous RPC interfaces in GWT I can’t find anything similar in Vaadin. Is there any way to add an AsyncCallback to an RPC call like it’s done in GWT or alternatively a clean way to check programmatically if the call has finished?
Sadly, using push is not a possibility due to customer requirements.

Long version:
The widget mentioned above is part of a component that is a unification of the FileDownloader extension and a Renderer for a grid column that allows to bind a file download to a grid row / item. It’s close to the
GridFileDownloader addon
which solves the problem mentioned above with a serverside flag and Thread.sleep until the corresponding RPC call is actually finished. Although this is a valid solution I hope there is a cleaner way to do this.

My current solution looks pretty much like this:

public void onClick(RendererClickEvent<JsonObject> event) {

However, the startDownload() function finishes before the Request of the RPC call has been send. I even tried using
but its the same problem here; the function returns false because the request logic hasn’t yet been started.

Any suggestions on how to solve this in a clean matter are greatly appreciated!

Asynchronous RPC return values (basically Futures) are a feature we have thought about, and even implemented a prototype. Currently the best way to simulate those is sending an “acknowledgement” RPC from the server when the RPC is received

Thanks for the insight but server to client rpc is not an option in this project.

However, I did solve the issue with help of the shared state. In case anyone has the same problem as I had, here is my solution:

I added a field to the shared state that is updated at the end of the rpc functions implementation on the serverside. The state change then triggers a method on the connector. That way the code in that method is only called after the rpc call has finished. I also added a boolean flag to ensure that the method is only executed if the rpc has been called before to prevent unintended execution (i.e. when the widget is being initialized).

I would still prefer a solution that just waits for the rpc call to finish as my current solution still needs additional code on the serverside and additional code for communication to handle the supposedly trivial issue of waiting for a response.

It is simply impossible to wait on the clientside for the call to finish due to JavaScript’s (and thus GWT’s single-threaded execution model. AJAX requests are inherently asynchronous and JS code cannot block without freezing the whole page. However, if you’re only interested in getting a notification when the request/response cycle ends, it is possible to add low-level connection listeners to ApplicationConnection:

  new CommunicationHandler() {

    void onRequestStarting(RequestStartingEvent e) {}

    void onResponseHandlingStarted(ResponseHandlingStartedEvent e) {}

    void onResponseHandlingEnded(ResponseHandlingEndedEvent e) {
        // Do stuff here

The onResponseHandlingEnded callback is probably most useful to you.

That is an interesting way to solve my issue.
I already implemented it and it’s definitely less code that is also confined to only the connector class. I’m still a bit worried about any potential side effects as it seems to be a feature that lies rather deep in the frameworks logic.

Thank you very much for your time and advice!