how to centralize loading screen for GWT RPC?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In GWT RPC applications, loading indicators often end up duplicated in every callback: show spinner before the call, hide spinner in success, hide spinner again in failure. A cleaner approach is to centralize that behavior in one reusable callback or service wrapper so every RPC call participates in the same loading policy automatically.
The Core Idea: Count Active RPC Calls
A centralized loading screen should not blindly hide itself after the first callback finishes, because several RPC requests may be running at once. The safest pattern is:
- increment a shared counter when a request starts
- show the loading overlay if the counter becomes non-zero
- decrement when a request finishes or fails
- hide the overlay only when the counter returns to zero
That avoids flicker and prevents one fast RPC from hiding the spinner while another slower request is still running.
A Simple Loading Manager
This class does not care which RPC method is running. It only tracks whether the application currently has unfinished requests.
Wrap AsyncCallback
The next step is to stop repeating loading logic in every RPC call. A custom callback base class works well for that.
Now client code becomes much cleaner:
The loading screen is now centralized without losing the ability to customize success or failure handling per request.
Centralize Even Further With a Service Helper
If you want to ensure every call uses the pattern, wrap the invocation itself:
Usage:
This keeps the loading logic completely out of individual presenters and widgets.
Common Pitfalls
The most common mistake is using a simple show/hide toggle without tracking concurrent requests. That works until two RPC calls overlap and the loading screen disappears too early.
Another issue is forgetting to decrement the counter in the failure path. If the spinner only hides on success, one failed request can leave the UI stuck in a permanent loading state.
A third pitfall is mixing local one-off spinners with a global loading manager inconsistently. Decide whether the spinner is application-wide or widget-specific and keep that policy coherent.
Finally, keep the centralized layer small. Its job is to manage loading state, not to become a giant RPC abstraction that hides too much application behavior.
Summary
- Centralize GWT RPC loading behavior with a shared loading manager instead of repeating spinner code in every callback.
- Track the number of active RPC calls so concurrent requests do not break the UI state.
- Wrap
AsyncCallbackto ensure success and failure both update the loading state. - A service helper can enforce the pattern across the client codebase.
- Keep the loading abstraction focused on UI state, not on unrelated business logic.

