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