Skip to content

Instantly share code, notes, and snippets.

@L3V147H4N
Last active February 26, 2016 00:41
Show Gist options
  • Save L3V147H4N/1169240ef1cc83c74456 to your computer and use it in GitHub Desktop.
Save L3V147H4N/1169240ef1cc83c74456 to your computer and use it in GitHub Desktop.
Promise Sequence
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