With multiple callbacks are attached to the same Deferred object the
first callback will be called with the argument(s) supplied to
Deferred.callback(). Then subsequent callbacks will be called with the
result of the previous callback. So according to your example the
second callback on d (which is writeln) will be called with the result
from the previous callback (which is the e object). Is this correct?
I thought I could restructure the example slightly and still get the
same end result but the following example does not print "write this".
I am sure it is obvious why this similar example does not work, but I
don't see it.
>>> d=new Deferred
Deferred(1, unfired)
>>> e=new Deferred
Deferred(2, unfired)
>>> d.addCallback(writeln)
Deferred(1, unfired)
>>> e.callback("write this")
>>> d.callback(e)
Deferred(2, success)
Thanks, I am starting to understand this stuff but not completely. Inyour example you never explicitly call e.addCallback() so when you calle.callback("write this") how does the e object choose the rightcallback function?
With multiple callbacks are attached to the same Deferred object thefirst callback will be called with the argument(s) supplied toDeferred.callback(). Then subsequent callbacks will be called with theresult of the previous callback. So according to your example thesecond callback on d (which is writeln) will be called with the resultfrom the previous callback (which is the e object). Is this correct?
I thought I could restructure the example slightly and still get thesame end result but the following example does not print "write this".I am sure it is obvious why this similar example does not work, but Idon't see it.d=new DeferredDeferred(1, unfired)e=new DeferredDeferred(2, unfired)d.addCallback(writeln)Deferred(1, unfired)e.callback("write this")d.callback(e)Deferred(2, success)
Ok, I've revised the implementation of Deferred to do this sanity
checking, and have added notes to the documentation for callback/
errback/addCallback/etc. that point out those edge cases.
-bob