Skip to content

Instantly share code, notes, and snippets.

@C-Rodg
Created October 10, 2017 22:54
Show Gist options
  • Save C-Rodg/f6f44981e667082b3e3ff95148f2b001 to your computer and use it in GitHub Desktop.
Save C-Rodg/f6f44981e667082b3e3ff95148f2b001 to your computer and use it in GitHub Desktop.
Example of doing a typically async action as synchronous with reduce() or async/await.
const itemIds = [1,2,3,4,5,6];
// Using reduce
itemIds.reduce((promise, id) => {
return promise.then(_ => api.deleteItem(id));
}, Promise.resolve());
// Using Async/Await
itemIds.forEach(async (item) => {
await api.deleteItem(item);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment