Skip to content

Instantly share code, notes, and snippets.

@Summerlve
Created July 27, 2015 06:19
Show Gist options
  • Save Summerlve/914ac09376833c2935e3 to your computer and use it in GitHub Desktop.
Save Summerlve/914ac09376833c2935e3 to your computer and use it in GitHub Desktop.
fake fo Promise.all
var all = (array) => {
return new Promise((resolve, reject) => {
var length = array.length;
var collect = [];
array.forEach((cur, index) => {
cur
.then(
(value) => {
collect[index] = value;
if (0 === --length) resolve(collect);
},
(error) => {
reject(error);
}
);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment