Embrace asynchrony!

Because you can't "wait" for the code to be downloaded and run, make you 
create() method asynchronous.

Another option in similar cases is to use an AsyncProxy but it won't work 
well with your ClientBundle 
scenario: 
http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/AsyncProxy.html

On Monday, July 15, 2013 9:22:26 AM UTC+2, dilantha wrote:
>
> Hi all,
>
> I have recently used code splitting to reduce the initial download file 
> size of my application. Here is my scenario. I have split the code in below 
> method .
>
> public <T extends ClientBundle> T create( int themeId )
>     {
>
>         switch ( themeId )
>         {
>             case THEME_1:
>
>                 GWT.runAsync( new RunAsyncCallback()// code split
>                 {
>                     @Override
>                     public void onFailure( Throwable reason )
>                     {
>                         Window.alert( "<< Code Split : Code download 
> failed [ThemeImpl.java::create] >>" );
>                     }
>
>                     @Override
>                     public void onSuccess()
>                     {
>                         resource = GWT.create( 
> WidgetResourceThemeWhite.class );
>                     }
>                 } );
>
>                 break;
>            
>         }
>
>         return ( T ) resource;
>     }
>
>
> Im creating a instance of *resource *inside onSuccess() of case 
> statement. but before it gets initialize the method return the value of 
> *resource. 
> *I want to return the value of *resource *only after its initialized. How 
> can this be done ? Thanks in advance.
>
>
> -- 
> Regards,
>
> Dilantha Silva,
> http://twitter.com/dilanthasilva | 
> http://www.linkedin.com/in/dilanthasilva|
> https://launchpad.net/~dilantha
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to