I am receiving a list of books from a database as a Promise.
If the initial list of books is successfully loaded, the books are further processed by passing them to
Modify the addInfo
method so it stores the promises in an array, and return Promise.all
instead, which will resolve when all the promises have resolved.
Assuming your methods returns a promise, and it looks like they do, something like
addInfo: function(books) {
let promises = books.map(function(book) {
return client.itemLookup({
idType : 'ISBN',
itemId : book.isbn,
responseGroup : 'ItemAttributes,Images'
}).then(function(results) {
return {
// The additional info from result gets added here
}
});
})
return Promise.all(promises); // catch errors where you call "addInfo"
}