Created
June 13, 2018 15:11
-
-
Save Horaddrim/45c2ff318c7b64c31e55a914314c423a to your computer and use it in GitHub Desktop.
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 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