Re: Avoid crashes, improve response, yes its XML-RPC asynchronous



On Wed, 2005-03-23 at 21:48 -0500, Seth Nickell wrote:

> Is syncronous. It could be converted to async like so:
> 
> function callYarrr(someDiv, someArg) {
>   var callback = new function(returnVal, error) {
>     if (error != None) reportException(error);
>     someDiv += "Remote call said: " + returnVal;
>   }
>   yarrr.remoteCall(somearg, callback);
> }
> 
> You can obviously call a "regular" function (i.e. not one dynamically
> created using new) too, but this has the advantage that all the code
> related to that operation is readable in one place, not hunt-n-search
> to figure out where the "rest of the method" is after the async
> returns. Also note that scoping is dynamic, so the callback function
> should still have access to someDiv even though it won't be called
> until callYarrr exits.

Although, not that this will not get the "this" reference right. "this"
will refer to the global scope, since this is a keyword that refers to
the current execution context, and not a variable (or something like
that).

I've tended to do:
var comment = this;
yarrr.remoteCall(somearg, function () { comment.someCallback(); }); 
to solve this.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a world-famous one-eyed card sharp haunted by memories of 'Nam. She's a 
provocative nymphomaniac bodyguard with her own daytime radio talk show. They 
fight crime! 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]