For all those instinctively pushing for synchronous RPC whenever
somebody "needs" it, please!  This is exactly a case where synchronous
network calls would be very bad, and just providing them because it's
"easier to understand" or whatever would mean people would design very
poor applications that don't consider network latency.  If you think
async from the beginning of your app design, there's practically no
cases where you "need" sync RPC; whereas if it was provided, people
would design apps like they were standalone, which is very difficult
to retrofit with async once you realize it's hanging everywhere...

Fomba, you wouldn't want a synchronous call here because your code
would stall on every iteration of the loop for a round trip call to
your server.  The onSuccess call *is* the indication to the client
that the async call has ended.  If you really need to know when all
calls have ended and your menu is complete in this code, you could add
a counter or something that you increment when making the call and
decrement on every onSuccess, and do something special once it reaches
0.  Better performance-wise thought would be to consider making this a
single call to get all the menus at once in a slightly more advanced
data structure, instead of many server calls done here.

On May 14, 10:02 am, fomba collins <fomba_coll...@yahoo.com> wrote:
> I have a method that uses the response of an asynchronous call. Here is it:
>  
> for(int i=0;i<listeOfApplications.size();i++) {
>  
>     menuItem.setText(listeOfApplications.get(i).toString());
>     MenuSetup ms1 =  new MenuSetup(menu, menuItem);
>      ms1.getSubMenus();
>       
>  }
>  
> During each iteraton, the getSubMenus() method has to be called. The 
> getSubMenus() is as follows:
>  
>
> public void getSubMenus(){
>  
> try {
> con.getSubMenus(menuItem.getText(), new AsyncCallback<ArrayList<String>>() {
>
>      public void onFailure(Throwable caught) {
>            System.out.println("Remote Procedure Call apps- Failure");
>  
>
> }
>
>      public void onSuccess(ArrayList<String> result) {
>         Menu men = new Menu();
>         for(int i =0; i< result.size();i++)
>         {
>         MenuItem menuItem1 = new MenuItem(result.get(i));
>         menuItem1.addSelectionListener(menuListener);
>         men.add(menuItem1);
>         }
>        menuItem.setSubMenu(men);
>        menu.add(menuItem);
>
> }
> });
> } catch (Exception e) {
>
> e.printStackTrace();}
>  
> }
>
>  
> Now, for each iteration on the listeOfApplications list, the getSubMenus() is 
> to be called. But what happens here is that all the iterations take place 
> before the getSubMenus() method starts execution.
> Is there a way to know on the client side that the execution of the 
> asynchronous call has ended? I need this to control my iterations. I have 
> tried wait(); but it does not work. Help!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to