What you want to do is have some method in the caller that is waiting
for the result that the callback can call once the data is retrieved.
So you would make the getUser() method return type void and, if the
class defining that method is the same as the one calling that method,
add another method handleUser(String s) which will be called from
within onSuccess.

Some examples : http://pastebin.com/t8aMbPq3



On Thu, Jun 17, 2010 at 1:51 AM, Joost Bloemsma
<joost.a.bloem...@gmail.com> wrote:
> Yep,
>
> I tried it too, but my wife didn't get the beer!!!
>
> On 16 jun, 15:07, Magnus <alpineblas...@googlemail.com> wrote:
>> Hi,
>>
>> thanks, the mechanism is still too new for me. Now, after debugging
>> exactly what Thomas said (the return val was empty), I understand it.
>>
>> So one can never just fetch something from the server while being in a
>> process where the server's result is needed.
>>
>> Good example! :-)
>>
>> Magnus
>>
>> On 16 Jun., 14:52, aditya sanas <007aditya.b...@gmail.com> wrote:
>>
>> > LOL Thomas.[?]
>>
>> > That was great example to determine async calls.
>>
>> > anyway what you are saying is right.
>>
>> > Its a bad design to have a method which returns something and then make
>> > async call which
>>
>> > changes the state of some variable.
>>
>> > --
>> > Aditya
>>
>> > On Wed, Jun 16, 2010 at 6:13 PM, Thomas Broyer <t.bro...@gmail.com> wrote:
>>
>> > > On Jun 16, 1:09 pm, Magnus <alpineblas...@googlemail.com> wrote:
>> > > > Hi,
>>
>> > > > because I cannot access a variable in the enclosing block from within
>> > > > an AsyncCallback method I found the following workaround with a class
>> > > > global variable, which I find very unpretty. How can one do this
>> > > > better?
>>
>> > > What is it that you don't understand in "asynchronous"?
>>
>> > > I mean, your getUsr call will *always* end after the "return
>> > > tmp_str_usr" statement. So, on the first call and until the server
>> > > responds and you AsyncCallback is called, you'll get the empty string
>> > > (initial value of the field); then AsyncCallback will change its
>> > > value, and on all subsequent calls until the server responds to the
>> > > new requests (and AsyncCallback will be called again) you'll get that
>> > > value.
>>
>> > > When you ask your wife to get you some beer, the beer won't be there
>> > > until your wife come back from the kitchen; and while she's gone, the
>> > > football match isn't paused and life continues.
>>
>> > > --
>> > > 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<google-web-toolkit%2bunsubs­cr...@googlegroups.com>
>> > > .
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/google-web-toolkit?hl=en.
>>
>> >  360.gif
>> > < 1 KBAnzeigenHerunterladen- Zitierten Text ausblenden -
>>
>> > - Zitierten Text anzeigen -
>>
>>
>
> --
> 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.
>
>

-- 
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