Created
January 25, 2018 09:35
-
-
Save jonaswide/162cbf0f9f68f74b096b4917528c1025 to your computer and use it in GitHub Desktop.
How to async (personal note)
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
| // Asuming both asyncProcess1 & asyncProcess2 takes 1 second each to proces | |
| // .. Foo would take 2 seconds to execute | |
| async function foo () { | |
| const dep1 = await asyncProcess1() | |
| const dep2 = await asyncProcess2() | |
| console.log(dep1, dep2) | |
| } | |
| // .. Bar would take 1 second tu execute | |
| async function bar () { | |
| Promise | |
| .all([asyncProcess1(), asyncProcess2()]) | |
| .then(([dep1, dep2]) => { | |
| console.log(dep1, dep2) | |
| }) | |
| } | |
| // .. Rap would take 1 second to execute | |
| async function rap () { | |
| const [dep1, dep2] = await Promise.all([asyncProcess1(), asyncProcess2()]) | |
| console.log(dep1, dep2) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment