Last active
April 18, 2019 14:47
-
-
Save wholypantalones/5935fee4989e5bbc75e67c06754dc260 to your computer and use it in GitHub Desktop.
Angular / Typescript Promise Resolver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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