Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
how to use GWT.runAsync()?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
aris  
View profile  
 More options Oct 31 2008, 12:39 pm
From: aris <ari09845...@gmail.com>
Date: Fri, 31 Oct 2008 09:39:41 -0700 (PDT)
Local: Fri, Oct 31 2008 12:39 pm
Subject: how to use GWT.runAsync()?
Hello
Is there any sample on how to use the GWT.runAsync(…) new method?

If I have:

public void onSuccess()
{
        objModule.startWorking();

}

And objModule.startWorking is a static method that creates a new
object and starts doing something… the compiler will put all the
objModule code in a separated file?

What happens if in another method I call objModule.method2() and
runAsync wasn’t called yet?

TIA


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Petersen  
View profile  
 More options Oct 31 2008, 12:50 pm
From: "Ian Petersen" <ispet...@gmail.com>
Date: Fri, 31 Oct 2008 12:50:04 -0400
Local: Fri, Oct 31 2008 12:50 pm
Subject: Re: [gwt-contrib] how to use GWT.runAsync()?

On Fri, Oct 31, 2008 at 12:39 PM, aris <ari09845...@gmail.com> wrote:
> If I have:

> public void onSuccess()
> {
>        objModule.startWorking();
> }

> And objModule.startWorking is a static method that creates a new
> object and starts doing something… the compiler will put all the
> objModule code in a separated file?

> What happens if in another method I call objModule.method2() and
> runAsync wasn't called yet?

Someone more knowledgable than me can correct me if I'm wrong, but
here's my understanding.

The compiler already analyzes your code to do things like dead code
removal.  In other words, it already removes code from the output that
it can prove will never be invoked.  The support for runAsync is
similar in that the compiler constructs some kind of call graph of
your code and any subgraph that's entirely behind a call to runAsync
gets broken out into a separate "fragment".  Each fragment is then
separately downloadable.

To more directly answer your question, the definition of startWorking
should be separated from the main module but method2 won't be.  Any
code that's called from startWorking and nowhere else should also be
separated from the main module, but anything that's called from
method2 would necessarily be included with the main module.  The
analysis gets more complicated as you add calls to runAsync, but the
traffic I've seen describing the design of runAsync makes it sound
like the compiler should be able to handle any combination (barring,
of course, any bugs that might still be lingering).

Ian


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lex Spoon  
View profile  
 More options Nov 5 2008, 5:16 pm
From: Lex Spoon <sp...@google.com>
Date: Wed, 5 Nov 2008 17:16:38 -0500
Local: Wed, Nov 5 2008 5:16 pm
Subject: Re: [gwt-contrib] Re: how to use GWT.runAsync()?

On Fri, Oct 31, 2008 at 11:50 AM, Ian Petersen <ispet...@gmail.com> wrote:
> The compiler already analyzes your code to do things like dead code
> removal.  In other words, it already removes code from the output that
> it can prove will never be invoked.  The support for runAsync is
> similar in that the compiler constructs some kind of call graph of
> your code and any subgraph that's entirely behind a call to runAsync
> gets broken out into a separate "fragment".  Each fragment is then
> separately downloadable.

That's it exactly.

>  Any
> code that's called from startWorking and nowhere else should also be
> separated from the main module, but anything that's called from
> method2 would necessarily be included with the main module.  The
> analysis gets more complicated as you add calls to runAsync, but the
> traffic I've seen describing the design of runAsync makes it sound
> like the compiler should be able to handle any combination (barring,
> of course, any bugs that might still be lingering).

It's a new tool, so we'll have to figure out the best coding idioms to
use it.  I believe, though, that you're best off if you can factor
your code so that you don't have much of the same code reachable via
two runAsync calls.  Instead, make one runAsync call, but let it take
a callback as a parameter.

That is, don't do this:

  void method1() {
    GWT.runAsync(/* ..method1 stuff.. */);
  }
  void method2() {
    GWT.runAsync(/* ..method2 stuff, similar to method1 stuff.. */);
  }

Instead, do it like this:

  class MyModule {
    interface Callback {  ... }
    static void runAsync(final Callback cb) {
      GWT.runAsync(new RunAsyncCallback() {
        void onSuccess() { cb.onSuccess(); }
        void onFailure() { Window.alert("doh!"); }
      }
    }

   void method1() {
     MyModule.runAsync(new Callback() { /*..method1 stuff..*/ });
   }
  void method2() {
     MyModule.runAsync(new Callback() { /*..method2 stuff..*/ });
   }

The compiler associates code fragments with calls to runAsync.  So,
the idea here is that you help the compiler identify a good chunk of
stuff to associate with the runAsync call in MyModule.runAsync.  If
you instead had method1 and method2 each call runAsync individually,
then the compiler would not be able to assign code to each of those
calls.

If you try this idiom, do make sure that you make your own callback
interface rather than usingRunAsyncCallback directly.  You want the
compiler to know that, within MyModule.runAsync, the call to
cb.onSuccess() will only call the callbacks related to MyModule, not
to any other callback in the system.

Lex Spoon


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google