Skip to content

Instantly share code, notes, and snippets.

@bang9
Created November 21, 2022 08:10
Show Gist options
  • Save bang9/433846fadb6d75dc10cf5fa8115f1ca2 to your computer and use it in GitHub Desktop.
Save bang9/433846fadb6d75dc10cf5fa8115f1ca2 to your computer and use it in GitHub Desktop.
Promise.all
const PromiseAll = (promises: Array<Promise<void>>) => {
return new Promise((resolve, reject) => {
let count = 0;
const results = new Array(promises.length);
promises.forEach((p, index) => {
p.then((result) => {
results[index] = result;
count++;
})
.catch((e) => {
reject(e);
})
.finally(() => {
if (count === promises.length) resolve(results);
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment