Skip to content

Instantly share code, notes, and snippets.

@jonaswide
Created January 25, 2018 09:35
Show Gist options
  • Save jonaswide/162cbf0f9f68f74b096b4917528c1025 to your computer and use it in GitHub Desktop.
Save jonaswide/162cbf0f9f68f74b096b4917528c1025 to your computer and use it in GitHub Desktop.
How to async (personal note)
// 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