Created
November 1, 2017 06:11
-
-
Save SastraNababan/8661e4efc815a14bc57bf7fa9ace9724 to your computer and use it in GitHub Desktop.
Async/await serial vs paralel
This file contains 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
const firstPromise= () => (new Promise((resolve,reject) => { | |
setTimeout(() =>{ resolve('first Promise')},1000) | |
})) | |
const secondPromise = () => ( new Promise((resolve,reject) =>{ | |
setTimeout(() =>{ resolve('second Promise')},1000) | |
})) | |
const thirdPromise = () => ( new Promise((resolve,reject) =>{ | |
setTimeout(() =>{ resolve('third Promise')},1000) | |
})) | |
async function asyncParalel() { | |
let a =firstPromise() | |
let b= secondPromise() | |
let c= thirdPromise() | |
console.log('done') | |
} | |
async function asyncSerial() { | |
let a= await firstPromise() | |
let b= await secondPromise() | |
let c= await thirdPromise() | |
console.log('done') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment