我使用的是嵌套Promise.all
,但最后Promise.all
并未解析。这是我的代码:
let eventPromises = [];
for(let event of events) {
event.customProperties = {};
let localPromises = [];
//map
let locationPromise = this.getEventLocation(event.latitude, event.longitude)
.then((address: LocationAddress) => {
if(address) {
event.customProperties.address = address;
}
console.log('----------location promise-----------')
return event;
});
localPromises.push(locationPromise);
//weather
let weatherPromise = this.getWeather(event.latitude, event.longitude)
.then(weatherInfo => {
event.customProperties.weather = weatherInfo;
});
localPromises.push(weatherPromise);
let eventPromise = Promise.all(localPromises).then(() => {
this.data.push(event);
console.log('----------localPromises done-----------')
return event;
});
eventPromises.push(eventPromise);
}
console.dir(eventPromises); //The __zone_symbol__state is always show null
Promise.all(eventPromises).then(() => {
console.log('----------------All events are done--------------------')
//Its neveer called
});
我想在eventPromises
解析后执行代码。