【发布时间】:2018-07-12 14:04:33
【问题描述】:
exports.AllDataCounts= function(req, res) {
var UserId = req.params.User_Id;
Promise.all([
Model.SchemaOne.count({ User_Id: UserId }).exec(),
Model.SchemaTwo.find({ User_Id: UserId }).exec()
]).then(response_One => {
console.log('response_One Success');
var _ids = response_One[1].map(x => x._id );
const GetMoreInfo = _id => {
Promise.all([
Model.Cube_SchemaThree.count({ Cube_Id: _id }).exec(),
Model.Cube_SchemaFour.count({ Cube_Id: _id }).exec(),
]).then( response_three => {
console.log('response_three Success');
return response_three ;
}).catch(error_3 => {
console.log('error');
return Cube_Id;
});
};
Promise.all(
_ids.map(_id=> GetMoreInfo(_id))
).then(response_two => {
console.log('response_two Success');
res.send({ Status:true, Response: { Output1: response_One, Output3: response_two });
}).catch( error_two = > {
res.send({ Status: false, Error: error_two, Message: 'Some Error Occurred' });
});
}).catch( error_one = > {
res.send({ Status: false, Error: error_1, Message: 'Some Error Occurred' });
});
};
我希望控制台输出是
response_一个成功
response_three 成功
response_Two 成功
但我得到的结果是
response_一个成功
response_Two 成功
response_三成功
如果我将删除 Promise.all 中的 GetMoreInfo 函数,它会正常工作
【问题讨论】:
标签: javascript node.js promise es6-promise