Created
July 6, 2018 14:04
-
-
Save mohokh67/411fd3cb0f1540eed9ec31aa822e6539 to your computer and use it in GitHub Desktop.
JavaScript ES6 async await
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 doubleMe(name, x) { | |
console.log('I am running ' + name); | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(x * 2); | |
console.log('hoooo'); | |
}, 2000); | |
}); | |
} | |
function helpMe(name, time) { | |
console.log('I am here to help you'); | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(60); | |
console.log('I helped you ' + name); | |
}, 1800); | |
}) | |
} | |
async function doAnotherJob() { | |
console.log('========================================= from here'); | |
const a = await helpMe('moho', 1000); | |
console.log(a); | |
const b = await helpMe('hoho', 80); | |
console.log(b); | |
const c = await helpMe('fery', 1000); | |
console.log(c); | |
} | |
async function doTheJob() { | |
console.log('========================================= from here'); | |
const a = await doubleMe('moho', 10); | |
console.log(a); | |
const b = await doubleMe('hoho', 30); | |
console.log(b); | |
const c = await doubleMe('fery', 80); | |
console.log(c); | |
} | |
//doAnotherJob(); | |
doTheJob(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment