Waiting for more than one event (using GWT)

I want to get two XML documents from the server and resume processing when they both arrived. Can I get them in parallel or do I need to refrain from issuing a second request before completing the first?

+3
source share
2 answers

Make both requests, then check if the other is complete, if the other is running, and continue if there is one.

private String responseOne;
private String responseTwo;

public startRequests() {
  makeAsyncRequestOne(new AsyncCallback<String>() {
    onSuccess(String response) {
      this.responseOne = response;
      if (responseTwo != null) {
        proceed();
      }
    }
  });

  makeAsyncRequestTwo(new AsyncCallback<String>() {
    onSuccess(String response) {
      this.responseTwo = response;
      if (responseOne != null) {
        proceed();
      }
    }
  });
}

As Chris points out, this can lead to a stream of maximum simultaneous requests to the same host name, so if you have many requests to send immediately, you can save the request queue and call the next one proceed()until the queue is exhausted.

, , , , .

+1

, , , . http://www.browserscope.org/?category=network ( " " , ). , IE < 8 2 !

, , . , -, / ( - ), , .

, XML, .

+2

Source: https://habr.com/ru/post/1794121/


All Articles