Correct way to write loops for promise.

后端 未结 13 1840
猫巷女王i
猫巷女王i 2020-11-22 15:20

How to correctly construct a loop to make sure the following promise call and the chained logger.log(res) runs synchronously through iterat

13条回答
  •  攒了一身酷
    2020-11-22 15:34

    How about this one using BlueBird?

    function fetchUserDetails(arr) {
        return Promise.each(arr, function(email) {
            return db.getUser(email).done(function(res) {
                logger.log(res);
            });
        });
    }
    

提交回复
热议问题