私は期待通りの結果を返さないpromise.all
関数を次のように書いています。Promise.allは[null、null]を返し、期待通りに返さない
if (Array.isArray(data)) {
return Promise.all(data.map((data) => {
hook.app.service('location')
.find({ query: { serviceLocationId:"100" } })
.then((result) => {
var startDept = result.data[0];
if (result.data.length > 0) {
data.problem.solutions.solution.routes.route.forEach((d) => {
d.stops.unshift({
serviceType: '',
orders: [],
travelTime:'',
travelDistance:'',
travelCost:'',
serviceTime: '',
serviceTimeCost:0,
tripNumber:0,
stopName : startDept.description,
arrivalTime:'',
departureTime : 36000.0,
locationType : startDept.locationType,
sequence : 0,
locationId : startDept.serviceLocationId,
lng : startDept.location.lng,
lat : startDept.location.lat
});
var endDept = d.stops.pop();
d.stops.push({
serviceType: '',
orders: [],
travelTime:endDept.travelTime,
travelDistance:endDept.travelDistance,
travelCost:endDept.travelCost,
serviceTime: '',
serviceTimeCost:0,
tripNumber:0,
stopName : startDept.description,
arrivalTime : endDept.arrivalTime,
departureTime:'',
locationType : startDept.locationType,
sequence : endDept.sequence,
locationId : endDept.locationId,
lng : startDept.location.lng,
lat : startDept.location.lat
});
});
hook.data = data;
combineArr = [];
return routes(hook).then((hook) => {
if ([hook.data].length > 0) {
combineArr.push(hook.data);
return combineArr;
} else {
next(new Error('routes response create failed'));
}
}).catch((err) => { return next(new Error(err.error)); });
} else {
next(new Error('no depo found'));
}
}).catch(err=>{ return next(new Error(err.error)); });
})).then((results) => {
console.log(results);
hook.result = results;
next();
});
}
約束は上記[null, null]
を返します。私は期待された結果を得ていない。これを解決するために私を助けてください。
を一読していてください[mcve]。それが何であるかを説明すれば、このような問題を診断して訂正するのに役立ちます(あるいは、まだそれを理解できなければ、他の人に助けを求めるときに使用する素晴らしい例があります)。 –