Asynchronously solution to check data from database kinds of loop clause

前端 未结 1 1584
迷失自我
迷失自我 2021-01-26 09:06

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

相关标签:
1条回答
  • 2021-01-26 09:12

    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?

    0 讨论(0)
提交回复
热议问题