Long running tasks

hi,
I have a case very similar to what is described here:

anyway I’m using hilla, and I can’t find an equivalent in hilla documentation.

Also please note that ListenableFuture is deprecated since spring 6.0 and you should use a CompletableFuture.

cheers,
Fernando

Hi,

I guess you already know how to handle that task correctly on the server side and you are focusing on the UI side.

In Hilla, server calls are asynchronous and don’t block the UI, so in principle there’s nothing special to do. Yet, there are some consequences. For example, you get a bar at the top of the window that shows that something is happening in the background and the application is waiting for something from the server. As it is normal that your task will take time, you probably don’t want that. To avoid the progress bar, you can use the mute property, introduced in 24.7:

SlowService.takesTime(someParam, { mute: true }).then((msg) => Notification.show(msg));

See How to create and use endpoints in Hilla | Vaadin for details.

Or, you can use a Flux and send a message when the task ends. This is more advanced, but has some advantages. For example, you can send more that one message, to let the client know about the progress of the task. And it can also reconnect automatically if the connection gets lost temporarily during the wait. See How to use reactive endpoints in Hilla | Vaadin for details and examples.

1 Like

You can also use a full-stack signal (experimental feature), which in turn uses Flux under the hood, but it add more features and avoids having to deal with Flux directly.

hi Luciano,
thank you for your quick response. So I won’t need the @Async annotation on the backend?

The full-stack-signal seems to fit better my use case. I can update a progress bar with that and provide fine grained status information.

hi again,
ahem… how do I set the value of a signal from the backend? The documentation speaks about set/replace/update methos but it seems these are available only on the frontend. Is this thing not bidirectional?

I was planning to use mute as you suggested, and push updates from the backend to update a progress bar and status messages.

This is hopefully coming to the V24.8. Might be irrelevant for your application, but then there would be the possibility of sharing Signals between Flow views and Hilla views, as well as setting the values from server-side codes.

2 Likes