我无法让Promise.all()等待物品。下面是我使用的代码。
请注意,这并非重复
const items = Object.keys(this.models).map(key => {
return this.processThenCallback(key).subscribe(() => {
this.populateItems(key);
return this.getOtherItems(key);
});
});
Promise.all(items).then(() => {
// Perform important function
});
我使用import 'rxjs/add/operator/map'
返回一个Observable;
private processThenCallback(key) {
return this.someService.getThings().map(data => {
// Do something on the data
));
}
private populateItems(key) {
// Perform synchronous process, nothing special
return key;
}
private getOtherItems(key) {
return this.otherService.getOtherItems().map(data => {
// Do something on data
));
}