Background operations
We don't want to block our UI when our app is performing a long-running operation, such as performing a network call or any database operations, because it makes the app unresponsive, which is inefficient and makes the end users unhappy.
Fortunately, TornadoFX provides the runAsync function. Any code placed inside a runAsync block will run in the background. If, say, the result from the background is required to update the UI that needs to be performed on JavaFX's application thread, then the ui block comes to the rescue.
The result of the runAsync function is available in the ui block, which can be used to update the UI.
In the following code snippet, we send an HTTP request in the background using the runAsync function ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access