I want to pass a parameter to a then
that is calculated from the information retrieved from a Promise
in the middle of my chain.
I have code that looks like this:
myPromise = new Promise(function(resolve,error){ resolve() });
myPromise
.then(function(){
return promiseQuery1();
})
// You can pass data by calling a later resolution function with a new promise.
.then(function(){
return new Promise(function(resolve,error){
// Save parameter in a local variable
var resolve_param;
anotherPromiseQuery()
// Generate param from data once query is done
.then(function(data){
console.log(data);
resolve_param = getSomethingFrom(data);
// And then say your new Promise is complete
}).then(function(){
resolve(resolve_param)
});
});
})
}
// This uses a param
.then(function(some_param){
console.log(some_param);
return someOtherPromise(some_param);
})
.then(function(){
console.log("Completed!");
})
The question is: Is this the best way to do it?