I can't make the Promise.all() wait for the items. Below are the codes that I used.
PLEASE NOTE THAT THIS IS NOT A DUPLICATE
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
});
I used import 'rxjs/add/operator/map'
to return an 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
));
}