Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to wait for all pending RPC requests to finish

    We have a complex set of screens that are presented in a TabSet in a Window. Various user actions can trigger DSRequests to add/update data in a number of different datasources. When the user closes the window we need to submit a final request to do some housekeeping tasks, but this final request must only be submitted after any other pending requests have completed.

    We have added a CloseClickEvent handler to the Window and I see that RPCManager has a requestsArePending() method, but how can I wait for all pending requests to finish? I tried this but it just starts an endless loop.
    Code:
    while (RPCManager.requestsArePending()) {
    	Timer t = new Timer() {
    		@Override
    		public void run() {
    			// Do nothing but wait.
    		}
    	};
    	t.schedule(300);
    }

    #2
    We would recommend just structuring your code so that ordinary callbacks are used to detect when all the relevant save operations have completed. requestsArePending() is really an API that was added for automated tests where this isn't an option, and could delay further than you intend if there are, for example, periodic polling or data refresh requests.

    If you really want to use requestsArePending(), to avoid an infinite loop you need to set a Timer, check once, set a new Timer, etc.

    Comment

    Working...
    X