How far will the GWT AsyncCallback run while waiting for a response?

If I needed to call a function (everything is written in Java):

public int hello() {
int a = 1;
executeCallback();
// C: Question lies in this range
return a;
}

public void executeCallback() {
// A: random code to execute before asynccallback
   randomClass.randomMethod(int a, int b, AsyncCallback<ReturnType>() {
      onSuccess();
      onFailure();
   });
// B: random code to execute after asynccallback
}

I understand that the material in comment A will be executed, and the non-synchronous randomMethod will be executed at the same time, and the comment will be executed in B.

I was wondering though, while randomMethod executes (if it takes a lot of time), the function will return to its caller (in this case, the hello method) and start executing the code in the C comment? Or will executeCallback wait for randomMethod to finish before it returns?

, , , randomMethod, C, "", , ?

+5
3

, , . , randomMethod AsyncCallback onSuccess OnFailure , B.. javascript- , onSuccess OnFailure executeCallBack.

, B C randomMethod, onSuccess, :

randomClass.randomMethod(int a, int b, AsyncCallback<ReturnType>() {
      onSuccess() {
         // B: random code to execute after asynccallback
        // C: Question lies in this range
        }
      }
      onFailure()
   });
+3

, , , " ".

. , . , - , AJAX.

, GWT ( JavaScript), , , . onModuleLoad() ClickHandler AsyncCallback GWT-RPC.

(, , ?) , , , ( ). . , , , - .

, hello() , (, onModuleLoad ClickHandler).

  • a = 1,
  • AJAX (randomClass.randomMethod),
  • AsyncCallback (, . , AsyncCallback).
  • B
  • A
  • .
+2

1] Asynchronous communication may take a little time to get used to. You must remember that the client continues the next statement immediately after calling the remote procedure, regardless of how long the procedure takes to complete on the server and transfer data from the server to the client.

2] You can execute // C: The question is in this range using the onSuccess method

+1
source

All Articles