I have a text box where the user can type in characters and a suggestion box opens up. I have fired events on the key up event . There is a timer set after which an async call is fired and on success of the async call the suggestion list is loaded. The problem is that when I start typing characters the loading symbol of the browser appears and it wont let me type any more characters in my text box till the async calls successfully returns and the suggestions are displayed. The point is that if the call is async why does the browser block events on the UI.
Following is the code . The fire event calls the async call and prints the end of fire event message. So the async call does not block. public void showSuggestions(final String query) {
ArrayList<PCTSuggestion> list;
System.out.println("Show Suggestions");
if (query.length() > 0) {
GWT.log(query);
list = cacher.getCachedvalues(query);
//list = new ArrayList<PCTSuggestion>();
if(list != null) {
if(!isTabOut() || !isBlurred()) {
display.showSuggestions(PCTSuggestBox.this, list, true, isAutoSelectEnabled(), suggestionCallback);
} else {
display.hideSuggestions();
}
} else {
this.fireEvent(new NewSuggestionEvent(query, limit));
System.out.println("End of Fire Event");
}
//display.showSuggestions(PCTSuggestBox.this, null, true, isAutoSelectEnabled(), suggestionCallback);
} else {
display.hideSuggestions();
}
}
there can be 1000 reasons why it is happening. AsyncCallbacks are not really so async. It only doesn't block UI thread when an actual HTTP requests is send. But constructing request, parsing response and processing callback body happens in UI thread as usual. Possible culprits:
I will not write down other 996 reason here, because it will be easier for you to actually measure what part of your code is slow.