Skip to content

Instantly share code, notes, and snippets.

@wholypantalones
Last active April 18, 2019 14:47
Show Gist options
  • Save wholypantalones/5935fee4989e5bbc75e67c06754dc260 to your computer and use it in GitHub Desktop.
Save wholypantalones/5935fee4989e5bbc75e67c06754dc260 to your computer and use it in GitHub Desktop.
Angular / Typescript Promise Resolver
purchaseOrderIds = ['12345', '67890'];
getPurchaseOrderDetails() {
const promises = [];
this.purchaseOrderIds.map(x => {
promises.push(new Promise((resolve) => {
this.purchaseOrderService.getPurchaseOrder(x)
.subscribe(
res => {
resolve(res);
},
err => {
console.error('error getting', x);
resolve(err);
}
);
}));
});
Promise.all(promises).then((completed) => {
this.purchaseOrderIds = completed;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment