Skip to content

Instantly share code, notes, and snippets.

@evidanary
Created March 29, 2016 18:04
Show Gist options
  • Select an option

  • Save evidanary/98cccb03608fc902bfaba44121287b62 to your computer and use it in GitHub Desktop.

Select an option

Save evidanary/98cccb03608fc902bfaba44121287b62 to your computer and use it in GitHub Desktop.
Demonstrating Promise.all
//Async load items from a remote API
loadItemsInStore(collection) {
this.setState({ isFetchingItemsFromRemote: true});
let promises = [];
for(let c of collection.values()) {
promises.push(ItemService.getItems(c.id));
}
let allPromises = Promise.all(promises);
//Fulfill the Promise
allPromises.then(() => {
this.setState({ isFetchingItemsFromRemote: false});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment