return makeFirstPromise()
.then(function(res1) {
(...)
})
.then(function(res2) {
(...)
})
.then(function(res3) {
// **here I need to access res1**
});
I would like to know if there is a best practice when I need to access to a previous promise result in a subsequent function of my promise chain.
I see two possible solutions:
var r1;
return makeFirstPromise()
.then(function(res1) {
r1 = res1;
(...)
})
.then(function(res2) {
(...)
})
.then(function(res3) {
console.log(r1);
});
or to nest the promises following the first but it visually breaks the chain sequence:
return makeFirstPromise()
.then(function(res1) {
(...)
return secondPromise(res2)
.then(function(res3) {
console.log(res1);
});
});
Any idea?