Skip to content

Instantly share code, notes, and snippets.

@Horaddrim
Created June 13, 2018 15:11
Show Gist options
  • Save Horaddrim/45c2ff318c7b64c31e55a914314c423a to your computer and use it in GitHub Desktop.
Save Horaddrim/45c2ff318c7b64c31e55a914314c423a to your computer and use it in GitHub Desktop.
function getSomething() {
return new Promise((resolve, reject) => setTimeout(() => resolve('Something'), 3000));
}
function getAnotherThing() {
return new Promise((resolve, reject) => setTimeout(() => resolve('Another thing'), 4000));
}
function anotherMain() {
return Promise.all([
getSomething(),
getAnotherThing(),
]).then((results) => {
console.log(results); // -> ['Something', 'Another thing']
});
}
// Com async/await
async function main() {
const results = await Promise.all([
getSomething(),
getAnotherThing(),
]);
console.log(results); // -> ['Something', 'Another thing']
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment