Last active
March 21, 2020 18:37
-
-
Save kerimdzhanov/1ee62e0c4464989c76d97d018625b265 to your computer and use it in GitHub Desktop.
Iterate through an array asynchronously one by one using the ES6 promises
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
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