What I want to do is asynchronously check from database and get a result from it? In my application I am trying to implement Asynchronously
to resolve this steps as
You can substitute Promise.all()
, Array.prototype.map()
for for
loop
function registeredUsers(data) {
return Promise.all(data.map(function(curr, i) {
var mobileNumber = curr.mobileNumber.substr(1, curr.mobileNumber.length);
return checkUserMobileNumberAsEwallet(mobileNumber)
.then(function (_mobileNumber) {
return {ewalletNumber: _mobileNumber};
});
}))
.then(function(accountNumbers) {
console.log(accountNumbers);
return accountNumbers
})
.catch(function(err) {
console.log(err);
})
}
see also How do I return the response from an asynchronous call?