Reputation: 439
I have 2 methods which return promises (shortened with non-async resolves)
function methodA () {
var d = $.Deferred();
d.resolve('A');
return d.promise();
}
function methodB (dependency) {
var d = $.Deferred();
// dependency would be used here
d.resolve('B');
return d.promise();
}
And then I have another method which chains these
function chainer () {
return methodA().then(function(result) {
return methodB(result);
});
}
And then I have another method which calls .when on this chainer
function main () {
$.when(chainer()).done(function (answer) {
console.log(answer);
});
}
The answer printed to the console is 'A', not 'B' as I would have expected! Why is this? And how can I get the result of methodB, since this method is dependant on methodA.
Thanks R
Upvotes: 0
Views: 58
Reputation: 439
Found the issue was due to a bug in jQuery. We use version 1.7.2, and the .then implementation has a bug. You need to still use the deprecated .pipe method. In later versions both work as expected.
Upvotes: 0