Skip to content

Instantly share code, notes, and snippets.

@kerimdzhanov
Last active March 21, 2020 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kerimdzhanov/1ee62e0c4464989c76d97d018625b265 to your computer and use it in GitHub Desktop.
Save kerimdzhanov/1ee62e0c4464989c76d97d018625b265 to your computer and use it in GitHub Desktop.
Iterate through an array asynchronously one by one using the ES6 promises
const array = []; // array to iterate
const promise = array.reduce((p, entry) => {
p.then(() => {
return new Promise((resolve, reject) => {...});
});
}, Promise.resolve());
promise
.then(() => console.log('done!'))
.catch(err => console.error(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment