I'm new to promise. I am trying to use promise to send queries to mysql db. After some queries I will use the result from the query, do some calculations and then use the output as some parameters of next query. Looks like the following:
firstQuery(). then(secondQuery). then(thirdQuery). then(fourthQuery). ...
Say, in the fourthQuery, I need to use results coming from firstQuery and secondQuery, and will have some additional calculations. How should I do that?
I know I can get the result from the previous promise by passing a parameter to the function:
then(thirdQuery). then(cal("I can only get output from thirdQuery here")). then(fourthQuery("pass output from cal"))
In this case, I don't any advantages of Promise over callbacks, because I can always write a function to simplify the repeated callbacks.