Sorry guys.. forgot to include the list on my last two posts to Jorge
- here's the most recent one.

Arnar

---------- Forwarded message ----------
From: Arnar Birgisson <[EMAIL PROTECTED]>
Date: 31.3.2006 16:20
Subject: Re: [mochikit] Help with passing information between deferred objects
To: Jorge Godoy <[EMAIL PROTECTED]>


Hi there,

2006/3/31, Jorge Godoy <[EMAIL PROTECTED]>:
> Hmmmm...  This makes things simpler, indeed.  Do you have any idea if and when
> this will go into the trunk instead of just being on a branch?

Nope, i'm not in the inner circles yet :o), don't really know how
things work here, if things like this are up to Bob Ippolito or what.
It's been in svn since Jan 22nd though..

> > var deferred1 = loadJSONDoc('url1')
> > var deferred2 = loadJSONDoc('url2')
> > var combinedDeferred = new DeferredList([deferred1, deferred2]);
> > combinedDeferred.addCallback(processResults)
>
> Could "deferred1" and "deferred2" be functions here?  As I said, "loadJSONDoc"
> doesn't work -- I haven't gone after why it doesn't work, but it doesn't...
> If it is the only way to have this working, then I'll have to dig why it is
> failing.

deferred1 and deferred2 need to be Deferred instances for this to
work. sendXMLHttpRequest() and doSimpleXMLHttpRequest() (from the
Async package) also return deferreds. But, then again, if loadJSONDoc
doesn't work, they might not work for the same reason.

If the only way for you is to use getXMLHttpRequest yourself and
handle the callback/readyState stuff your self, you will need to
create generic deferreds (with "new Deferred()"), add them to a
DeferredList, and then call .callback() on them when the
XMLHttpRequest result is available.

In code:

var deferred1 = new Deferred();
var deferred2 = new Deferred();
var combinedDeferred = new DeferredList([deferred1, deferred2]);
combinedDeferred.addCallback(processResults)

var req1 = getXMLHttpRequest();
req1.onreadystatechange = function () {
   if (req1.readyState == 4) deferred1.callback(evalJSONRequest(req1));
};

var req2 = getXMLHttpRequest();
req1.onreadystatechange = function () {
   if (req2.readyState == 4) deferred2.callback(evalJSONRequest(req2));
};

req1.open('GET', url1, true);
req1.send();

req2.open('GET', url2, true);
req2.send();

Sorry if my XMLHttpRequest code is off, to be honest I haven't done
this directly since I discovered MochiKit and loadJSONDoc() /
sendXMLHttpRequest() :o))

I think you should look into getting loadJSONDoc to work though, it
will make your life so much better :o)

> > function processResults(returnValues) {
> >   var call1succeeded = returnValues[0][0];
> >   var call1result = returnValues[0][1];
> >   var call2succeeded = returnValues[1][0];
> >   var call2result = returnValues[1][1];
>
> Is it recommended to always store / use this "succeeded" value?  'cause I'm
> using the syntax

Nope, that's just one way of using DeferredList (the default way).
DeferredList never calls errback (if I remember correctly) by default.
This can be changed with some constructor parameters. See
http://twistedmatrix.com/projects/core/documentation/howto/defer.html#auto7
for details. The parameter in question is fireOnOneErrback.

> I was reading it last night. :-)  I guess if I was more awake I would have
> seen "DeferredList" somewhere.  I'll read it again...

Direct link above :o)

Arnar

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

Reply via email to