Please keep in mind that I am new to node.js and I am using Android development.
My scenario is as follows:
- Run a database query that returns zero or a value
- Call the web service with this database value, which offers paginated information, which means that when I call, I get the option to transfer the next call if there is additional information to retrieve.
- After all the items are retrieved, save them in the database table.
- If all is well, for each item received earlier, I need to make a different web call and save the received information in a different table.
- If any data cannot be selected, all data must be returned from the database.
So far I have tried this:
getAllData: function(){
self.getMainWebData(null)
.then(function(result){
}
}
getMainWebData: function(nextPage){
return new Promise(function(resolve, reject) {
module.getWebData(nextPage, function(errorReturned, response, values) {
if (errorReturned) {
reject(errorReturned);
}
nextPage = response.nextPageValue;
resolve(values);
})
}).then(function(result) {
if (nextPage) {
self.getMainWebData(nextPage)
}
})
There are a few things that are missing, from what I tested, getAllData.then runs only one for the first set of elements, and not for the other, so it is not so clear to process the returned data.
LATER EDIT: I edited the script. Given some additional research, I feel like I can use the chain or .then()to perform operations in sequence.
source
share