Last active
February 26, 2016 00:41
-
-
Save L3V147H4N/1169240ef1cc83c74456 to your computer and use it in GitHub Desktop.
Promise Sequence
This file contains hidden or 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
function promiseSequence (array, values = [], fnName, args = []) { | |
return new Promise((resolve, reject) => { | |
if (array.length !== 0) { | |
array[0][fnName].apply(array[0], args) | |
.then(data => { | |
values.push(data); | |
array.splice(0, 1); | |
promiseSequence(array, values, fnName, args) | |
.then(() => { | |
resolve(values); | |
}) | |
.catch(err => { | |
reject(err); | |
}); | |
}) | |
.catch(err => { | |
reject(err); | |
}); | |
} else { | |
resolve(values); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment