Reputation: 1
In GWT, an asynchrounous call is already in progress and i will fire an event after completing this call. If we refresh the browser now, that event is firing but the process is not completing, how can i solve this. Please help.
This is the code block i am using:
private void rpcMethod(final String nounToTrack, final ImportResultDTO importResult, final String selectedNounName) {
service.checkNounImportExportStatus(nounToTrack, new AsyncCallback<String>() {
@Override
public void onFailure(final Throwable caught) {
if (caught instanceof StatusCodeException) {
eventBus.fireEvent(new CurrentNotificationChangedEvent(true));
} else {
caught.printStackTrace();
rpcToRemoveNounImportExportStatusAttribute(nounToTrack);
}
clearDataGridHeaders();
}
@Override
public void onSuccess(final String result) {
if (result.equals(BodDeskMessageConstants.COMPLETED) || result.contains(BodDeskMessageConstants.EXCEPTIONSTATUS)) {
if (result.contains(BodDeskMessageConstants.EXCEPTIONSTATUS)) {
eventBus.fireEvent(new CurrentNotificationChangedEvent(true));
} else {
log.info("new notification is occurring..... 3");
eventBus.fireEvent(new CurrentNotificationChangedEvent(true));
}
} else {
rpcToCheckNounImportExportStatus(nounToTrack, importResult, selectedNounName);
}
}
});
}
if the rpc call failed/succeeded, we are firing an event to see the new notification avaialble. Now, i started this rpc call, i refreshed the browser while the rpc call is executing. The event is firing but the process is not completed. Please suggest how to restrict the firing of the event ?
Upvotes: 0
Views: 92
Reputation: 64561
When you unload the page (which also happens when you refresh it), all ongoing requests are aborted and you get a StatusCodeException
with a getStatusCode()
of 0
(note: you'll get the same behavior whichever the trigger for aborting the request: network error, etc.)
You could then check the status code in your onFailure
, but if you don't want false positives for other cases of status code 0, you'll have to listen for WindowClosingEvent
and set a flag there. Just be sure to set the flag back at some other event (e.g. a successful response, or non-0 failure) in case the user cancels the navigation.
Upvotes: 1